mainstreetop Posted March 1, 2010 Share Posted March 1, 2010 I think I need to set up an associative array... Here's my query: $sql = 'SELECT item.*, attributes.* FROM item LEFT JOIN attributes ON item.ProductNumber = attributes.ProductNumber WHERE item.ProductNumber = 9503731'; $result = mysql_query($sql); while ($row = mysql_fetch_array($results)) { $ProductNumber = $row['ProductNumber']; $AttribPriority = $row['AttributePriority']; $AttribName = $row['AttributeName']; $AttribValue = row['AttributeValue']; $Att_array = array($AttPriority, $AttName, $AttValue); } This is how the data is stored in the 'attribute' table: ProductNumber AttributePriority AttributeName AttributeValue 9503731 4 Clerk Totalizers [Nom] 4 9503731 5 Compartments 4 Bill Drawer 9503731 5 Compartments 5 Coin Drawer I can not figure out how to store these multiple attributes so I can render them on the web page. I tried setting up a foreach to display the contents of the array: foreach ($Att_array as $AttValues) { echo $AttValues; // this is where I get lost... } I need to be able to display EACH AttributePriority, AttributeName & AttributeValue. I know I'm missing something... just not sure what it is. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/193785-how-to-store-multiple-occurrence-of-same-variable-in-array/ Share on other sites More sharing options...
Goat Posted March 1, 2010 Share Posted March 1, 2010 Why don't you just output it all in while loop using echo? Anyway try this $att_array = array(); while ($row = mysql_fetch_array($results)) { array_push($att_array, $row); } Now you have everythin neatly stored in 2d array. Link to comment https://forums.phpfreaks.com/topic/193785-how-to-store-multiple-occurrence-of-same-variable-in-array/#findComment-1019944 Share on other sites More sharing options...
mainstreetop Posted March 1, 2010 Author Share Posted March 1, 2010 @ GOAT... Thank you for responding. I am sorry, but I am very new to all of this. I do not fully understand how I would echo out each of the attributes. Also, I did not include the full contents of my WHILE statement (not sure if it makes a difference), but I am pulling fields from other tables, too. I only showed the $row[''] 's pertaining to the attributes. Does your suggestion then apply for everything with the WHILE statement? Hopefully, that made sense. Link to comment https://forums.phpfreaks.com/topic/193785-how-to-store-multiple-occurrence-of-same-variable-in-array/#findComment-1019951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.