2013-03-14 8 views
0

나는 여기에 올리는 것에 의지해야했다.while 루프 내의 substr PHP SQL

필자는 성공적으로 인쇄 할 수있는 배열을 가지고 있지만 문자를 인쇄하는 방법을 제한해야합니다. 나는 이것이 substr을 사용하여 수행 할 수 있다는 것을 알고 있지만, 나는 제한 할 가치가있는 substr을 배치 할 수 없다.

한 줄에 $ variable = substr을 사용하는 것으로 알고 있지만 사용하고있는 배열을 구현할 수 없으며 문제를 명확히 할 수는 있지만 어쩔 수없이 쓸모없는 문서를 모두 검색했습니다.

코드에 Heres 코드 (이 경우에는 $ info 배열과 .info [ 'post_content'])를 지정합니다.

mysql_connect("localhost", "xxxxxxxx", "xxxxxxx") or die(mysql_error()); 
mysql_select_db("xxxxxxxxx") or die(mysql_error()); 
$data = mysql_query("SELECT * FROM posts WHERE hushfeed_showon = 1") 
or die(mysql_error()); 
    } 

while($info = mysql_fetch_array($data)) 
{ 


echo "<div> 
<ul class='blocks-thumbs thumbs-rollover'> 
    <li> 
     <a href='single.html' class='thumb' title='An image'><img src='img/dummies/282x150.gif' alt='Post' /></a> 
     <div class='excerpt'> 
      <a href='dnb/a_Post.php?postid=".$info['postid']."' class='header'>".$info['post_title'] ."</a> 
      <p class='para1'>" .$info['post_content']."</p> 

     </div> 
     <a href='single.html' class='link-button'><span>Read more &#8594;</span></a> 
    </li> 

</ul> 
</div>"; 



} 

임 내가 에코 동안 기간 사용에 대한 모든 정보를 찾을 수있는 "$를.."

사람이이 많은 것 SUBSTR 내가 처리 할 수 ​​국한 할 위치에 도움이 되거 수 있다면 어려움을 겪고 고맙다!

감사합니다.

스투

+0

'의 SUBSTR'(number_of_chars_you_want_printed $ 정보 [ 'POST_CONTENT'], 0,)? –

+0

"에코 도중 마침표 사용에 대한 정보를 찾을 수 없어서 고심하고 있습니다." "$. "''- 문자열 연쇄 (http://de2.php.net/manual/en/language.operators.string.php) –

+0

PHP 문서를 보았습니까? 거기에'substr '을 사용하는 방법에 대한 예제가 많이 있습니다. –

답변

0
<?php 
echo "[...]<p class='para1'>" . 
     (strlen($info['post_content'])>200? 
      substr($info['post_content'],0,200)."...": 
      $info['post_content']). 
     "</p>[...]"; 

하고 쉬운 버전 :

<?php 
echo "[...]<p class='para1'>" . substr($info['post_content'],0,200) . "</p>[...]"; 
+0

건배 존! 굉장한 작품, 지금 내가 잘못 가고있는 곳을 정확하게보고, 많은 감사합니다 !! – Derple