Jump to content

Working with arrays and queries - index problem


priory

Recommended Posts

Hi,

 

I think this should be fairly simple but I'm a noob. I am trying to post back a list of item names that match a query. The tables look like

 

[itemName, ItemKey]

[basketKey, ItemKey]

 

When given a particular basket key I tried selecting all ItemKeys that matched and then adding them to an array, I then tried using that array to search for the ItemName and return it as an array to echo:

 


$itemselect = mysql_query("SELECT ItemKey FROM temp_basket WHERE BasketKey = '$sessionid'");
while ($itemresult = mysql_fetch_array($itemselect))
{


$itemvariable = $itemresult['ItemKey'];

$itemlookupquery = mysql_query("SELECT ItemName FROM item_lookup WHERE ItemKey = '$itemvariable'");
$itemnamearray = mysql_fetch_array($itemlookupquery);
$itemname = $itemnamearray[0];
echo $itemname;

}

 

The problem is it seems to be returning all the results in one index position so the results come out as one long unformatted string. Do I manually have to increase the index position using a loop or is there a better way?

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.