limiting chats from a sql text

Discussion in 'PHP' started by danielldf, Apr 23, 2010.

  1. #1
    <?
    
    while ($row = mysql_fetch_object($result)) {
    
    
    
    	$fldid=$sno=$row->fldid;
    
            $fldquestion=$row->fldquestion;
    
    	$fldtype=$row->fldtype;
    
    	$fldexaminer=$row->fldexaminer;
    
    ?>
    
      <tr>
    
        <td><?=$sno?></td>
    
        <td bgcolor="#FFFFFF"><?=$fldquestion?></td>
    PHP:
    Hi, the $fldquestion get from mysql a question.. but some questions are huge how can i show just the first 20 characters from that field??

    ;) thankz
     
    danielldf, Apr 23, 2010 IP
  2. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use PHP's substr() to chop of everything after the first 20 characters.
     
    Imozeb, Apr 23, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    As Imozeb suggested use substr(), if you look at the documentation theirs a few useful examples which you can build upon:

    http://php.net/manual/en/function.substr.php

    <?php
    
    while ($row = mysql_fetch_object($result)) {
    
        $fldid=$sno=$row->fldid;
    
        $fldquestion=$row->fldquestion;
    
        $fldtype=$row->fldtype;
    
        $fldexaminer=$row->fldexaminer;
    
    ?>
    
      <tr>
    
        <td><?php echo $sno; ?></td>
    
        <td bgcolor="#FFFFFF"><?php echo substr($fldquestion, 0, 20); ?></td>
    PHP:
     
    danx10, Apr 24, 2010 IP