stmosaic Posted September 5, 2017 Share Posted September 5, 2017 I've got some code that works well until I hit Sept listing. $sql = "SELECT * FROM LPV_boatSchedule ORDER BY syear, smonth, sday"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $IDENT=$row['ID']; $SDAY=$row['sday']; $SYEAR=$row['syear']; $STIME=$row['stime']; $SNAME=$row['sname']; echo " <tr valign\"top\" bgcolor=\"#FFD2A6\"> <td width=\"18%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=2>"; if ($row['smonth'] == 01){echo "January";} if ($row['smonth'] == 02){echo "February";} if ($row['smonth'] == 03){echo "March";} if ($row['smonth'] == 04){echo "April";} if ($row['smonth'] == 05){echo "May";} if ($row['smonth'] == 06){echo "June";} if ($row['smonth'] == 07){echo "July";} if ($row['smonth'] == 08){echo "August";} if ($row['smonth'] == 09){echo "September";} if ($row['smonth'] == 10){echo "October";} if ($row['smonth'] == 11){echo "November";} if ($row['smonth'] == 12){echo "December";} echo " $SDAY, $SYEAR</font></td> Displays all months with their names EXCEPT August & September. Data is correct in the database. This has confounded me for days. Any suggestions as to the cause? Quote Link to comment https://forums.phpfreaks.com/topic/304874-if-statement-displays-for-most-but-not-others/ Share on other sites More sharing options...
Barand Posted September 5, 2017 Share Posted September 5, 2017 (edited) Remove the 0's from the number values. A leading 0 implies octal notation so only digits 0-7 are valid. Hence O8 and O9 are not valid numbers. Use DATE types instead of separate fields, then all that processing can be done simply within the query. You can also use datetime objects to format the date as required with a single line of code. Edited September 5, 2017 by Barand 1 Quote Link to comment https://forums.phpfreaks.com/topic/304874-if-statement-displays-for-most-but-not-others/#findComment-1550793 Share on other sites More sharing options...
stmosaic Posted September 5, 2017 Author Share Posted September 5, 2017 But won't that mess with my ordering in the sql statement? Quote Link to comment https://forums.phpfreaks.com/topic/304874-if-statement-displays-for-most-but-not-others/#findComment-1550794 Share on other sites More sharing options...
stmosaic Posted September 5, 2017 Author Share Posted September 5, 2017 Thanks Barand. Guess I need to figure out how to redo DB and code for that. Date Objects have always confused me and now with the lupus the confusion is even worse. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/304874-if-statement-displays-for-most-but-not-others/#findComment-1550796 Share on other sites More sharing options...
Barand Posted September 5, 2017 Share Posted September 5, 2017 Only if you wrongly store numbers as string values. As I said in the edit, use DATE types (YYYY-MM-DD format) Quote Link to comment https://forums.phpfreaks.com/topic/304874-if-statement-displays-for-most-but-not-others/#findComment-1550798 Share on other sites More sharing options...
Barand Posted September 5, 2017 Share Posted September 5, 2017 With the data you have now $y = 2017; $m = 9; $d = 5; echo (new dateTime("$y-$m-$d"))->format('F jS Y'); //---> September 5th 2017 Quote Link to comment https://forums.phpfreaks.com/topic/304874-if-statement-displays-for-most-but-not-others/#findComment-1550799 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.