Hello,
Basically I'm trying to create a simple shopping cart.
I have a table in my database with some products in, and I am trying to pull the products from the database into a multidimensional array then display the results in a table.
The code I am using to put the results into an array is as follows:
$results = array();
while ($row = mysql_fetch_array($result))
$results[] = $row;
Now I have no idea if that is the correct way to do it, because this is the first time I am using arrays and I'm getting very confused.
I used the command "print_r" to show me the contents of the array and it seems a bit of a mess (but it could be right for all I know).
The contents of the array looks like this:
Array ( [0] => Array
( [0] => 3 [id] => 3
[1] => tshirt [name] => tshirt
[2] => 323 [price] => 323 )
[1] => Array
( [0] => 4 [id] => 4
[1] => Boots [name] => Boots
[2] => 33 [price] => 33 )
[2] => Array
( [0] => 5 [id] => 5
[1] => Sun Glasses [name] => Sun Glasses
[2] => 33 [price] => 33 )
)
It's when I try to display the results properly in a table that I get all sorts of problems, the latest of which is that I try to list the names of all the products in the table, but instead it ends up just showing the id, name, and price from the first result.
Can anybody please confirm that I am putting the results into an array correctly please, and maybe guide me on the best way to display the results.
I've tried hunting around the Internet but there aren't many useful links that I can find for putting mysql results into an array then displaying them.
Thanks very much, help is much appreciated.