Jump to content

[SOLVED] PHP Table Format Help


Clinton

Recommended Posts

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

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 */
	}
}
}
?>

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?

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;
}
?>

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.