justinh Posted November 24, 2008 Share Posted November 24, 2008 Trying to figure out whats wrong with this code: $count = mysql_num_rows($result); $count1 = 1; while($hey = mysql_fetch_array($result)){ echo "<font size=2 color=white>".$count1.".".$hey['lastname'].",".$hey['firstname']."<br>"; $count1++; if ($count1 == 2 and $count > 2){ echo "<a href=\"moreinfo.php\"><font size=2>[...]</a><br>"; break; } } no errors come back.. but nothing is displaying.. not even $count1. It should display 2 results, and if there is more than 2, then display [...] Quote Link to comment Share on other sites More sharing options...
trq Posted November 24, 2008 Share Posted November 24, 2008 This.... ($count1 == 2 and $count > 2) will never evaluate to true. It makes no sense. How can something equal two yet also be larger than two? As for why the while doesn't seem to execute. have you error checked your query? Does $result actually contain a resultset? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 if nothing is being echoed, there is either an error, and error reporting is not on. or there are no results returned. try this code instead: $count = mysql_num_rows($result); if(!$count){ print "NO ROWS FOUND"; exit; } $count1 = 0; while($hey = mysql_fetch_array($result)){ echo "<font size=2 color=white>".$count1.".".$hey['lastname'].",".$hey['firstname']."<br>"; $count1++; if ($count1 == 2 && $count > 2){ echo "<a href=\"moreinfo.php\"><font size=2>[...]</a><br>"; break; } } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 This.... ($count1 == 2 and $count > 2) will never evaluate to true. It makes no sense. How can something equal two yet also be larger than two? As for why the while doesn't seem to execute. have you error checked your query? Does $result actually contain a resultset? thorpe, they are 2 different variables. one is a counter and one is the total number of rows. it basically tests if it's the second result and there are more results Quote Link to comment Share on other sites More sharing options...
trq Posted November 24, 2008 Share Posted November 24, 2008 Hehe, again (today) i should be more carefull reading other peoples code. Didn't see the 1. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 easy mistake...that is why i don't use things like $count, $count1, $count2 ... too easy to mix up Quote Link to comment Share on other sites More sharing options...
justinh Posted November 24, 2008 Author Share Posted November 24, 2008 $count = mysql_num_rows($result); if(!$count){ echo "<font size=5>no rows found"; } else { echo "<font size=5>rows found"; } $count1 = 1; while($hey = mysql_fetch_array($result)){ echo "<font size=2 color=white>".$count1.".".$hey['lastname'].",".$hey['firstname']."<br>"; $count1++; if ($count1 == 2 and $count > 2){ echo "<a href=\"moreinfo.php\"><font size=2>[...]</a><br>"; break; } } not even displaying no rows found, or rows found. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 at the top of your script, put: ini_set('display_errors',1); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
justinh Posted November 24, 2008 Author Share Posted November 24, 2008 No errors reported. <?php ini_set('display_errors',1); error_reporting(E_ALL); include("connect.php"); function NavigateCalender($month, $year){ $cur = strtotime($year . '-' . $month . '-01'); if (isset($_GET['direction'])){ switch($_GET['direction']){ case "1": list($year,$month) = explode('-',date('Y-m',strtotime('-1 month',$cur))); break; case "2": list($year,$month) = explode('-',date('Y-m',strtotime('+1 month',$cur))); break; } } return(array($month,$year)); } $date = time(); $day = date('d',$date); $month = (isset($_GET['month']))?$_GET['month']:date('m',$date); $year = (isset($_GET['year']))?$_GET['year']:date('Y',$date); list($month,$year) = NavigateCalender($month,$year); $firstday = mktime(0,0,0, $month, 1, $year); $title = date('F', $firstday); $dayofweek = date('D', $firstday); switch($dayofweek){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } switch($month){ case "01": $MonthDisplay = "January"; break; case "02": $MonthDisplay = "Febuary"; break; case "03": $MonthDisplay = "March"; break; case "04": $MonthDisplay = "April"; break; case "05": $MonthDisplay = "May"; break; case "06": $MonthDisplay = "June"; break; case "07": $MonthDisplay = "July"; break; case "08": $MonthDisplay = "August"; break; case "09": $MonthDisplay = "September"; break; case "10": $MonthDisplay = "October"; break; case "11": $MonthDisplay = "November"; break; case "12": $MonthDisplay = "December"; break; } $daysinmonth = date('t',strtotime($year . '-' . $month . '-01')); echo "<html><head> </head><body bgcolor=black><p align=\"Center\"><img src=\"logo.gif\" class=\"indexlogo\"><span class=login><table width=\"80%\" cellpadding=4 cellspacing=0 border=1 bordercolor=#0099CC bgcolor=#003399><tr> <td align=center colspan=7><font face=white size=6 color=white><a href=\"?direction=1&month=" . $month . "&year=" . $year . "\">< </a>" . $MonthDisplay . " - ". $year . "<a href=\"?direction=2&month=" . $month . "&year=" . $year . "\"> ></a></font></p></div></td></tr> <p align=center> <tr>"; echo '<td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Sunday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Monday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Tuesday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Wednesday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Thursday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Friday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Saturday</font></td></tr>'; $daycount = 1; echo "<tr>"; while ($blank > 0){ echo '<td bgcolor="#0080C0" width="14%" align="left" valign="top"><div align="right"><font color="" face="Arial" size="2"> <b><Br></b></font></div><font color="#FFFFFF" face="Arial" size="2"> <br><br><br></font></td></td>'; $blank = $blank-1; $daycount++; } $daynum = 1; while($daynum <= $daysinmonth){ $processid = $month.$daynum.$year; $result = mysql_query("SELECT * FROM reservations WHERE reservationdate = $processid"); $num = mysql_num_rows($result); if ($num >= 1){ if ($daynum == $day && $month == date('m',$date)){ echo "<td bgcolor=\"#004C73\" border=\"1\" width=\"14%\" align=\"left\" valign=\"top\"><div align=\"right\"><font color=\"green\" face=\"Arial\" size=\"2\"> <b><a href=\"process.php?id=".$processid."\"><font color=white>".$daynum."</a></b></font></div></font><br>"; $count = mysql_num_rows($result); if(!$count){ echo "<font size=5>no rows found"; } else { echo "<font size=5>rows found"; } $count1 = 1; while($hey = mysql_fetch_array($result)){ echo "<font size=2 color=white>".$count1.".".$hey['lastname'].",".$hey['firstname']."<br>"; $count1++; if ($count1 == 2 and $count > 2){ echo "<a href=\"moreinfo.php\"><font size=2>[...]</a><br>"; break; } } echo '</td>'; echo "</td>"; $daynum++; $daycount++; if($daycount > 7){ echo "</tr><tr>"; $daycount = 1; } } else { echo "<td bgcolor=\"#0099CC\" border=\"1\" width=\"14%\" align=\"left\" valign=\"top\"><div align=\"right\"><font color=\"green\" face=\"Arial\" size=\"2\"> <b><a href=\"process.php?id=".$processid."\"><font color=\"white\">".$daynum."</b></font></div> <br><br><br></font></td>"; $daynum++; $daycount++; if($daycount > 7){ echo "</tr><tr>"; $daycount = 1; } } }else { if ($daynum == $day && $month == date('m',$date)){ echo "<td bgcolor=\"#0080C0\" width=\"14%\" align=\"left\" valign=\"top\"><div align=\"right\"><font color=\"green\" face=\"Arial\" size=\"2\"> <b><a href=\"process.php?id=".$processid."\"><font color=red>".$daynum."</b></font></div> <br><br><br></font></td>"; $daynum++; $daycount++; if($daycount > 7){ echo "</tr><tr>"; $daycount = 1; } } else { echo "<td bgcolor=\"white\" width=\"14%\" align=\"left\" valign=\"top\"><div align=\"right\"><font color=\"green\" face=\"Arial\" size=\"2\"> <b><a href=\"process.php?id=".$processid."\"><font color=black>".$daynum."</b></font></div> <br><br><br></font></td>"; $daynum++; $daycount++; if($daycount > 7){ echo "</tr><tr>"; $daycount = 1; } } } } while($daycount >= 1 && $daycount < 7){ echo "<td></td>"; $daycount++; } echo "</tr></table>"; ?> Don't know if this could come in handy but here is the live version: http://www.wmptest.com/HuntReserver/calender.php Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 no offense, but wow what a mess. it's virtually impossible to follow your code logic without proper indentation. i will say though, that the snippet of code we have been going back and forth about is inside an if statement: $result = mysql_query("SELECT * FROM reservations WHERE reservationdate = $processid"); $num = mysql_num_rows($result); if ($num >= 1){ so "no rows found" will never be reached Quote Link to comment Share on other sites More sharing options...
justinh Posted November 24, 2008 Author Share Posted November 24, 2008 Yes i know its a mess, It's basically abunch of stuff i've been recently learning, thrown together. I do need to learn how to organize the code a little better i guess. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 here is a start...here is your code formatted nice and neat: <?php ini_set('display_errors', 1); error_reporting(E_ALL); include ("connect.php"); function NavigateCalender($month, $year) { $cur = strtotime($year . '-' . $month . '-01'); if (isset ($_GET['direction'])) { switch ($_GET['direction']) { case "1" : list ($year, $month) = explode('-', date('Y-m', strtotime('-1 month', $cur))); break; case "2" : list ($year, $month) = explode('-', date('Y-m', strtotime('+1 month', $cur))); break; } } return (array ( $month, $year )); } $date = time(); $day = date('d', $date); $month = (isset ($_GET['month'])) ? $_GET['month'] : date('m', $date); $year = (isset ($_GET['year'])) ? $_GET['year'] : date('Y', $date); list ($month, $year) = NavigateCalender($month, $year); $firstday = mktime(0, 0, 0, $month, 1, $year); $title = date('F', $firstday); $dayofweek = date('D', $firstday); switch ($dayofweek) { case "Sun" : $blank = 0; break; case "Mon" : $blank = 1; break; case "Tue" : $blank = 2; break; case "Wed" : $blank = 3; break; case "Thu" : $blank = 4; break; case "Fri" : $blank = 5; break; case "Sat" : $blank = 6; break; } switch ($month) { case "01" : $MonthDisplay = "January"; break; case "02" : $MonthDisplay = "Febuary"; break; case "03" : $MonthDisplay = "March"; break; case "04" : $MonthDisplay = "April"; break; case "05" : $MonthDisplay = "May"; break; case "06" : $MonthDisplay = "June"; break; case "07" : $MonthDisplay = "July"; break; case "08" : $MonthDisplay = "August"; break; case "09" : $MonthDisplay = "September"; break; case "10" : $MonthDisplay = "October"; break; case "11" : $MonthDisplay = "November"; break; case "12" : $MonthDisplay = "December"; break; } $daysinmonth = date('t', strtotime($year . '-' . $month . '-01')); echo "<html><head> </head><body bgcolor=black><p align=\"Center\"><img src=\"logo.gif\" class=\"indexlogo\"><span class=login><table width=\"80%\" cellpadding=4 cellspacing=0 border=1 bordercolor=#0099CC bgcolor=#003399><tr> <td align=center colspan=7><font face=white size=6 color=white><a href=\"?direction=1&month=" . $month . "&year=" . $year . "\">< </a>" . $MonthDisplay . " - " . $year . "<a href=\"?direction=2&month=" . $month . "&year=" . $year . "\"> ></a></font></p></div></td></tr> <p align=center> <tr>"; echo '<td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Sunday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Monday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Tuesday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Wednesday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Thursday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Friday</font></td> <td bgcolor="#0099CC" width="14%" align="center" valign="middle"><font color="#FFFFFF" face="Arial" size="2">Saturday</font></td></tr>'; $daycount = 1; echo "<tr>"; while ($blank > 0) { echo '<td bgcolor="#0080C0" width="14%" align="left" valign="top"><div align="right"><font color="" face="Arial" size="2"> <b><Br></b></font></div><font color="#FFFFFF" face="Arial" size="2"> <br><br><br></font></td></td>'; $blank = $blank -1; $daycount++; } $daynum = 1; while ($daynum <= $daysinmonth) { $processid = $month . $daynum . $year; $result = mysql_query("SELECT * FROM reservations WHERE reservationdate = $processid"); $num = mysql_num_rows($result); if ($num >= 1) { if ($daynum == $day && $month == date('m', $date)) { echo "<td bgcolor=\"#004C73\" border=\"1\" width=\"14%\" align=\"left\" valign=\"top\"><div align=\"right\"><font color=\"green\" face=\"Arial\" size=\"2\"> <b><a href=\"process.php?id=" . $processid . "\"><font color=white>" . $daynum . "</a></b></font></div></font><br>"; $count = mysql_num_rows($result); if (!$count) { echo "<font size=5>no rows found"; } else { echo "<font size=5>rows found"; } $count1 = 1; while ($hey = mysql_fetch_array($result)) { echo "<font size=2 color=white>" . $count1 . "." . $hey['lastname'] . "," . $hey['firstname'] . "<br>"; $count1++; if ($count1 == 2 and $count > 2) { echo "<a href=\"moreinfo.php\"><font size=2>[...]</a><br>"; break; } } echo '</td>'; echo "</td>"; $daynum++; $daycount++; if ($daycount > 7) { echo "</tr><tr>"; $daycount = 1; } } else { echo "<td bgcolor=\"#0099CC\" border=\"1\" width=\"14%\" align=\"left\" valign=\"top\"><div align=\"right\"><font color=\"green\" face=\"Arial\" size=\"2\"> <b><a href=\"process.php?id=" . $processid . "\"><font color=\"white\">" . $daynum . "</b></font></div> <br><br><br></font></td>"; $daynum++; $daycount++; if ($daycount > 7) { echo "</tr><tr>"; $daycount = 1; } } } else { if ($daynum == $day && $month == date('m', $date)) { echo "<td bgcolor=\"#0080C0\" width=\"14%\" align=\"left\" valign=\"top\"><div align=\"right\"><font color=\"green\" face=\"Arial\" size=\"2\"> <b><a href=\"process.php?id=" . $processid . "\"><font color=red>" . $daynum . "</b></font></div> <br><br><br></font></td>"; $daynum++; $daycount++; if ($daycount > 7) { echo "</tr><tr>"; $daycount = 1; } } else { echo "<td bgcolor=\"white\" width=\"14%\" align=\"left\" valign=\"top\"><div align=\"right\"><font color=\"green\" face=\"Arial\" size=\"2\"> <b><a href=\"process.php?id=" . $processid . "\"><font color=black>" . $daynum . "</b></font></div> <br><br><br></font></td>"; $daynum++; $daycount++; if ($daycount > 7) { echo "</tr><tr>"; $daycount = 1; } } } } while ($daycount >= 1 && $daycount < 7) { echo "<td></td>"; $daycount++; } echo "</tr></table>"; ?> 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.