brooksh Posted March 1, 2009 Share Posted March 1, 2009 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; Link to comment https://forums.phpfreaks.com/topic/147397-solved-putting-sql-results-into-an-array/ Share on other sites More sharing options...
trq Posted March 1, 2009 Share Posted March 1, 2009 "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; Link to comment https://forums.phpfreaks.com/topic/147397-solved-putting-sql-results-into-an-array/#findComment-773657 Share on other sites More sharing options...
brooksh Posted March 1, 2009 Author Share Posted March 1, 2009 Thanks. That works. Link to comment https://forums.phpfreaks.com/topic/147397-solved-putting-sql-results-into-an-array/#findComment-773661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.