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 Quote 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 } Quote 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!!!!! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.