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? Link to comment Share on other sites More sharing options...
Barand Posted September 5, 2017 Share Posted September 5, 2017 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. Link to comment 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? Link to comment 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! Link to comment 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) Link to comment 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.