newb Posted August 9, 2010 Share Posted August 9, 2010 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. Quote Link to comment Share on other sites More sharing options...
newb Posted August 9, 2010 Author Share Posted August 9, 2010 can anybody help? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 9, 2010 Share Posted August 9, 2010 What if there isn't 5 results? What's your code doing wrong? Quote Link to comment Share on other sites More sharing options...
newb Posted August 9, 2010 Author Share Posted August 9, 2010 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) Quote Link to comment Share on other sites More sharing options...
newb Posted August 9, 2010 Author Share Posted August 9, 2010 can anybody help? Quote Link to comment Share on other sites More sharing options...
newb Posted August 9, 2010 Author Share Posted August 9, 2010 fixed i thnk.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.