here I get the sites under category
I open the div if only $i = 1 or 11 or 21
and close the div if $i = 10 or 20 or 30
but I want to close the div if there is no more sites under the category regardless of the value of $i
how can I do this??
11-05-2012, 02:55 AM
simplypixie
You need to find out how many records you have from your query and then compare $i to that number. I can't see your query so can't give exact help, but say you have got the num_rows and allocated that number to a variable $total_rows, you would just add this in
You can also do a much more simple if statement by checking for a remainder when $i is divided by 10 (i.e. if 10 divided by 10 = 0 then you are on the 10th record):
PHP Code:
if ($i%10 == 0 || $i == $total_rows)
11-05-2012, 03:21 AM
Mohammed Zayan
here I have 2 query
one for the category
and one for the sites
the first query is
PHP Code:
$query = "SELECT `cat_id`,`description` FROM dalil_cats";
the second is
PHP Code:
$sites_query = "SELECT `cat_id`,`link`,`photo` FROM dalil";
if I get the num_rows for the result of $sites_query I'll have the number of all sites
I view the sites under category
and I want to close the div in 2 conditions if
PHP Code:
$i%10 == 0 && there is no more sites under the category
11-05-2012, 11:29 AM
simplypixie
In which case, why not run your $sites_query within the while / foreach loop for your $query and then you can just get the sites per category (using the category id) and will be able to easily solve your problem.
11-05-2012, 12:43 PM
Mohammed Zayan
can you give me an example?
11-05-2012, 12:47 PM
simplypixie
Not exactly as I don't have your full code (as in I don't know how or where you are running your queries) but within this
PHP Code:
<?php if(isset($cats)): ?> <?php foreach($cats as $cat): ?>