Jump to content

[SOLVED] Putting sql results into an array


brooksh

Recommended Posts

Not sure what I'm doing wrong, but I just want the results to be $array = "image1,image2,image3";

 

$sql = "SELECT imagename FROM images WHERE id = '$id'";	
         $result = mysql_query($sql);
      while($row = mysql_fetch_array($result))
            {
                        $result_array[] = $row['imagename];
            }
$array = $result_array;

"image1,image2,image3";

 

Is a string, not an array.

 

$sql = "SELECT imagename FROM images WHERE id = '$id'";	
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_array($result)) {
      $result_array[] = $row['imagename'];
    }
  }
}
$str = implode(',',$result_array);
echo $str;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.