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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/101622-solved-php-table-format-help/ 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 */ } } } ?> Link to comment https://forums.phpfreaks.com/topic/101622-solved-php-table-format-help/#findComment-519955 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? Link to comment https://forums.phpfreaks.com/topic/101622-solved-php-table-format-help/#findComment-519960 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. Link to comment https://forums.phpfreaks.com/topic/101622-solved-php-table-format-help/#findComment-519961 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. Link to comment https://forums.phpfreaks.com/topic/101622-solved-php-table-format-help/#findComment-519964 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; } ?> Link to comment https://forums.phpfreaks.com/topic/101622-solved-php-table-format-help/#findComment-519967 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. Link to comment https://forums.phpfreaks.com/topic/101622-solved-php-table-format-help/#findComment-522973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.