php - How split a string separated by comma? -


i want display string in comma separated comma

here code

function getitemids() {     $i=0;      $query="select item_id common.items order item_id desc limit 10";     $str="";      $result= mysql_query($query);      while($result1= mysql_fetch_row($result))     {          if($i==0)          {            $str .= $result1[0];          }           else          {          $str .=",".$result1[0];          }       }         echo $strs;      } 

but here print str have output 12345678 want 1,2,3,4 please me

thanks in advance

a better way:

function getitemids($num = 10) {     $q = "select item_id common.items order item_id desc limit " . $num;     $result = mysql_query($q);     $ids = array();     while($row = mysql_fetch_assoc($result)) {         $ids[] = $row['item_id'];     }     return implode(',', $ids); }  echo getitemids(); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -