hmaloney Posted June 11, 2007 Share Posted June 11, 2007 Hi, I am sure this will take someone in the know about 5 seconds to fix! I am putting the results of a recordset into a multidimensional array, but when I try and display the items in that array, I am only displaying the first one, and then the results are empty after that, no matter how many items are actually in the array. I can't figure out why. This is my code: $strsql = "SELECT ProductID, Title, ImageURL FROM Products WHERE CategoryID = ".$myCatID." AND Available = 1"; $rs = mysql_query($strsql); $arrProd[] = mysql_fetch_array($rs); //** this must be where things are going awry $z = mysql_num_rows($rs); // I know that the value of $z is correct and matches the number of items that the query should return $startingPoint = 0; $endingPoint = 5; if ($endingPoint > $z) { $endingPoint = $z; } for ($y = $startingPoint; $y < $endingPoint; $y++) { echo <img src='productimages/".($arrProd[$y]['ImageURL'])."'>"; echo "<br />".($arrProd[$y]['Title']); } Thanks heaps for your help!!! Heather Link to comment https://forums.phpfreaks.com/topic/55042-simple-problem-with-a-multi-dimensional-array-of-a-mysql-recordset/ Share on other sites More sharing options...
btherl Posted June 11, 2007 Share Posted June 11, 2007 It should be like this: while ($row = mysql_fetch_array($rs)) { $arrProd[] = $row; //** this must be where things are going awry } Link to comment https://forums.phpfreaks.com/topic/55042-simple-problem-with-a-multi-dimensional-array-of-a-mysql-recordset/#findComment-272090 Share on other sites More sharing options...
hmaloney Posted June 11, 2007 Author Share Posted June 11, 2007 Thanks heaps!!!!! Link to comment https://forums.phpfreaks.com/topic/55042-simple-problem-with-a-multi-dimensional-array-of-a-mysql-recordset/#findComment-272099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.