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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.