Jump to content

HELP!! how to add a minimum $i counter instead of maximum??


newb

Recommended Posts

ok here is my code:

it has a counter variable $i at the start which basically acts as a maximum cutoff for how much data can be output. i have this variable set at 5.

 

how can i make it so that it doesnt cut off the results (outputs the full 7 days worth of results if available), but ALWAYS outputs a minimum of 5 results?

 


$now = $now-(7*24*60*60); // Display 7 Days of Results
$query = mysql_query("SELECT * FROM table WHERE date >= '$now' ORDER BY max(date) desc");
$i = 0;
while ($row = mysql_fetch_assoc($query)) {
$cid = $row['cat_id'];
$title = $row['name'];
$seoname = cleanurl($title,0);

		$img = 'images/'.$seoname.'.jpg';
	if (!file_exists($img)) {
		$img = '';
	} else {
		$img = 'images/'.$seoname.'.jpg';
	}		

	if (!empty($img)) {	
		$i++;
	}

	if (!empty($img) && $i <= 5) { // Always show ATLEAST 5 results
	echo '<img src="'.$img .'" style="width:528px;" alt="" />' . "\n";
	}
}

 

Please help and look at my code..thanks.

there's over 10,000 rows of data in the table so there will always be results.

 

im trying to get the code to output whatever the maximum results there is from the query given, but always output a minimum number of 5 results at the least (it wont always output 5 results because some days will not have any rows, so it should look to the next days until a minimum of atleast 5 results are output)

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.