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?

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.