Clinton Posted April 17, 2008 Share Posted April 17, 2008 I have the code below but the output Date of Birth and CDL Dates are running together in the Date of Birth Box. I've tore it apart in my designer program but I can't figure it out. Any ideas? <tr> <td>Name:</td> <td>Date of Birth:</td> <td>CDL License Expire:</td> </tr> <?php while ($row=mysql_fetch_assoc($result)){ extract($row); echo"<tr> <td>$lname $fname $mname</td> <td>"; if ($dob=='0000-00-00') echo " "; else echo date('n/j/Y',strtotime($dob)); "</td> <td>"; if ($cdl=='0000-00-00') echo " "; else echo date('n/j/Y',strtotime($cdl)); "</td> </tr>"; } ?> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 Ok, I just cleaned up your code, and commented it, so you can see what logic PHP sees when it attempts to run it. Functionally, it's accurate, but I don't think you intended it to work this way: <tr> <td>Name:</td> <td>Date of Birth:</td> <td>CDL License Expire:</td> </tr> <?php while ($row=mysql_fetch_assoc($result)){ extract($row); /* Echo their name (Last, First, Middle)*/ echo" <tr> <td>$lname $fname $mname</td> <td>"; /* If we don't have their date of birth --> */ if ($dob=='0000-00-00'){ /* Print " " and quit */ echo " "; } /* If we don't --> */ else{ /* Print their DOB, then move on to their CDL License */ echo date('n/j/Y',strtotime($dob)); "</td> <td>"; /* If they have their CDL --> */ if ($cdl=='0000-00-00'){ echo " "; /* Quit */ } /* If we do --> */ else{ echo date('n/j/Y',strtotime($cdl)); "</td> </tr>"; /* Quit */ } } } ?> Quote Link to comment Share on other sites More sharing options...
Clinton Posted April 17, 2008 Author Share Posted April 17, 2008 You now, I thought it might have been an else / if problem I just didn't know how to figure it out. I see what you are saying here but I've got about 48 columns I'm going to need when all is said and done. :-| Would it functionally be better to do something like this? <?php while ($row=mysql_fetch_assoc($result)){ extract($row); echo ?> <tr> <td> <?$lname $fname $mname;?> </td> <td> <? if ($dob=='0000-00-00') echo " "; else echo date('n/j/Y',strtotime($dob)); ?> </td> <td> <? if ($cdl=='0000-00-00') echo " "; else echo date('n/j/Y',strtotime($cdl)); ?> </td> </tr> <? } ?> Or does it not matter because it will essentially run together? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 umm..no. that's bad code. give me a couple to re-do it for you. Quote Link to comment Share on other sites More sharing options...
Clinton Posted April 17, 2008 Author Share Posted April 17, 2008 Ok, I appreciate the help. I've been figuring out this stuff pretty well but this one is tricking me up. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 fixed: <?php while ($row=mysql_fetch_assoc($result)){ extract($row); /* ##################### */ /* DOB Check */ /* ##################### */ if ($dob=='0000-00-00'){ $dob = " "; } else{ $dob = date('n/j/Y',strtotime($dob)); } /* ##################### */ /* END DOB Check */ /* ##################### */ /* ##################### */ /* CDL Check */ /* ##################### */ if ($cdl=='0000-00-00') { $cdl = " "; } else{ $cdl = date('n/j/Y',strtotime($cdl)); } /* ##################### */ /* END CDL Check */ /* ##################### */ echo <<<END <tr> <td> $lname, $fname, $mname</td> <td> $dob </td> <td> $cdl </td> </tr> END; } ?> Quote Link to comment Share on other sites More sharing options...
Clinton Posted April 21, 2008 Author Share Posted April 21, 2008 Thanks a million. That was another great learning experience for me and it works like a charm. 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.