If you need to show your items later at the page, you could store them in an array and later show anywhere you wish ...
You could use the code Zangeel has provided, but instead of outputting the entries right away you could store them in an array (I do not know you column names, so I am giving some arbitrary names just to show the idea):
PHP Code:
$q = mysql_query("SELECT * FROM `products`");
$items = array();
$counter = 0;
while ($row = mysql_fetch_assoc($q))
{
$items['item_name'] = $row['item_name'];
$items['price'] = $row['price'];
++counter;
}
// You could output your array $items entries later at the page
If items have some field containing item category, I would also reformat the array by categories to make it simpler to work with it. If you show your table `products` structure, I could be more specific and show the idea more clearly.
The table structure could be obtained with the MySQL command
Code:
SHOW CREATE TABLE `products`;
Also if you need to move all your resultset to an array (without any formatting), you could do it simpler (also a modification of code provided by Zangeel):
PHP Code:
$q = mysql_query("SELECT * FROM `products`");
while ($row = mysql_fetch_assoc($q))
{
$items[] = $row;
}
// You could output your array $items entries later at the page
// Some reformatting of the array $items could be possibly useful
Again: I think it would be possible to be much more specific if your posted your table `products` structure.
Also normally I move such code to a class methods. It simplifies the code reusing if necessary and also makes page code more readable ...