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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.