Travis959 Posted October 6, 2011 Share Posted October 6, 2011 This is kind of hard to explain, but I will try my best. I have a script that is attempting to display information in a MySQL database by month fields that are chosen by the user. For instance, they can choose for the start date to start in January, and pick the end date which in this example will be April. The script then puts the required field that match the specific dates into a column for each month. For the most part it outputs fine as: Jan: 15, Feb: 14, Mar: 9, Apr: 2. However, sometimes there is nothing in the database for certain months. This causes the script to display wrong so instead I get: Jan 3, Feb: , Mar: , Apr: . In the above example, the Jan: 3 might be wrong, because the field might have been for Mar instead. I need it to display like this when there is no fields in the database: Jan: 0, Feb: 0, Mar: 3, Apr: 0. How would I go about doing this? Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted October 6, 2011 Share Posted October 6, 2011 if(mysql_num_rows($query) > 0){// checks to make sure it found at least one match //proceed with code } this will check and make sure that if a match is not found.. it will not display anything. Quote Link to comment Share on other sites More sharing options...
mike12255 Posted October 6, 2011 Share Posted October 6, 2011 if it is still not working could you post your code please Quote Link to comment Share on other sites More sharing options...
Travis959 Posted October 6, 2011 Author Share Posted October 6, 2011 This is the code I'm using. I'm not sure how the above code is supposed to figure out where there are no rows at. Anyways, it's still not working. Also, my $i7 variable is not getting incremented with "$i7++", it always returns 1 regardless, as I was going to compare the $i7 to the month field in the database. $startmonth2 = ltrim($startmonth, '0'); $i7 = $startmonth2; $searchdatabase8 = "SELECT * FROM slssum2 WHERE company = '$companyname' AND CONCAT(year,month) BETWEEN '$startyear$startmonth' AND '$endyear$endmonth' AND field3 = '$field6_3' AND field4 = '$field6_4' AND field5 = '$field6_5' AND month = '$field7_month' AND year = '$field7_year' ORDER BY field3,field4,year,month ASC"; $run8 = mysql_query($searchdatabase8) or die (mysql_error()); while($row8 = mysql_fetch_assoc($run8)) { $field8_10 = $row8['field10']; $field8_month = ltrim($row8['month'], '0'); if(mysql_num_rows($row8) > 0){ echo '<td bgcolor="#ccffcc" width="25px"><strong>'; echo $field8_10; echo '</strong></td>'; } else { echo '<td bgcolor="#ccffcc" width="25px">0</td>'; } $i7++; } } 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.