Jump to content

If statement displays for most, but not others


stmosaic

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.