Jump to content

Simple problem with a multi-dimensional array of a mysql recordset


hmaloney

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.