Page 1 of 1
how to make DIV to print specific number of times
Posted: Thu Nov 24, 2011 11:19 am
by biosynthesis
Code: Select all
for ($i = 1; $i < 6; $i++) {
$categoryName = translateNumToCategory($i);
$dbProducts = mysql_query('SELECT * FROM ' . $categoryName . " WHERE Promo = 1");
while ($product = mysql_fetch_array($dbProducts)) {
$promoimg = '<div><img src="product_images/' . $product['Image'] . '" width="57" height="53" alt="Pic" /></div>';
echo $promoimg;}
}
How can i make php to print $promoimg only 6 times ?
Re: how to make DIV to print specific number of times
Posted: Thu Nov 24, 2011 11:45 am
by Celauran
Add a LIMIT clause to your query.
Re: how to make DIV to print specific number of times
Posted: Thu Nov 24, 2011 12:11 pm
by mikeashfield
Code: Select all
<?php
for ($i = 1; $i < 6; $i++) {
$categoryName = translateNumToCategory($i);
$dbProducts = mysql_query('SELECT * FROM ' . $categoryName . " WHERE Promo = 1 LIMIT 0,6;");
while ($product = mysql_fetch_array($dbProducts)) {
$promoimg = '<div><img src="product_images/' . $product['Image'] . '" width="57" height="53" alt="Pic" /></div>';
echo $promoimg;}
}
?>
Re: how to make DIV to print specific number of times
Posted: Thu Nov 24, 2011 12:23 pm
by biosynthesis
It seems that it does not work any other suggestions?
Re: how to make DIV to print specific number of times
Posted: Thu Nov 24, 2011 12:35 pm
by Celauran
Code: Select all
SELECT * FROM tablename WHERE Promo = 1 LIMIT 6
There's no reason this won't work.
Re: how to make DIV to print specific number of times
Posted: Thu Nov 24, 2011 1:04 pm
by biosynthesis
DIVs not showing at all.
Re: how to make DIV to print specific number of times
Posted: Fri Nov 25, 2011 6:10 am
by maxx99
first redo:
Code: Select all
$dbProducts = mysql_query('SELECT * FROM ' . $categoryName . " WHERE Promo = 1 LIMIT 0,6;");
to
Code: Select all
$q = 'SELECT * FROM ' . $categoryName . " WHERE Promo = 1 LIMIT 0,6;"
echo $q; //temporarily
$dbProducts = mysql_query($q);
Are you sure that you have 5 tables with $categoryName you have?
Copy your select statements and exec it with "MySQL Workbench" or something, check if it returns any results. If no, there's your problem

Re: how to make DIV to print specific number of times
Posted: Fri Nov 25, 2011 7:17 am
by biosynthesis
maxx99 wrote:first redo:
Code: Select all
$dbProducts = mysql_query('SELECT * FROM ' . $categoryName . " WHERE Promo = 1 LIMIT 0,6;");
to
Code: Select all
$q = 'SELECT * FROM ' . $categoryName . " WHERE Promo = 1 LIMIT 0,6;"
echo $q; //temporarily
$dbProducts = mysql_query($q);
Are you sure that you have 5 tables with $categoryName you have?
Copy your select statements and exec it with "MySQL Workbench" or something, check if it returns any results. If no, there's your problem

Your method works. Thank you.