Jump to content

How to store multiple occurrence of same variable in array


mainstreetop

Recommended Posts

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.

 

@ 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.

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.