Forum Moderators: coopster
<?
$Query = "Select *";
$Query = $Query . ", DATE_FORMAT(eFrom , '%m/%d/%Y') as eFrom";
$Query = $Query . ", DATE_FORMAT(Thru , '%m/%d/%Y') as Thru";
$Query = $Query . ", DATE_FORMAT(FirstBillable , '%m/%d/%Y') as FirstBillable";
$Query = $Query . " FROM episodedata WHERE MR = '" . $MR . "' ORDER BY 'eFrom' DESC";
$Result = mysql_query($Query,$Link);
$Num = mysql_numrows($Result);
{
$i=0;
while ($i < $Num)
{
$eFrom=mysql_result($Result,$i, 'eFrom');
$Thru=mysql_result($Result,$i,"Thru");
$Status=mysql_result($Result,$i, "Status");
$Firstb=mysql_result($Result,$i,"FirstBillable");
$ID=mysql_result($Result,$i,"EpisodeID");
++$i;
?>
<tr>
<td width="150" class="List"><center><a href="episode_detail.php?EpisodeID=<?= $ID?>"><?= $eFrom?></a></center></td>
<td width="150" class="List"><center><a href="episode_detail.php?EpisodeID=<?= $ID?>"><?= $Thru?></a></center></td>
<td width="150" class="List"><center><?= $Firstb;?></center></td>
<td width="150" class="List"><center><?= $Status;?></center></td>
</tr>
<?
if ($i < $Num) {
$eFrom=mysql_result($Result,$i,"eFrom");
$Thru=mysql_result($Result,$i,"Thru");
$Status=mysql_result($Result,$i, "Status");
$Firstb=mysql_result($Result,$i,"FirstBillable");
$ID=mysql_result($Result,$i,"EpisodeID");
?>
<tr>
<td width="150" class="List2"><center><a href="episode_detail.php?EpisodeID=<?= $ID?>"><?= $eFrom?></a></center></td>
<td width="150" class="List2"><center><a href="episode_detail.php?EpisodeID=<?= $ID?>"><?= $Thru?></a></center></td>
<td width="150" class="List2"><center><?= $Firstb;?></center></td>
<td width="150" class="List2"><center><?= $Status;?></center></td>
</td>
</tr>
<?
++$i;
}
}
}
?>
Here is the problem!:
Normaly when i DATE_FORMAT() the sql query it formats my date with the arguments, it works on all other 15 of my pages but for some reason it just wont work here. The only difference between this page and all the other pages is the fact that im using the MYSQL_NUMROWS and then instead of $Variable=$Row['Var'] im using the $Variable=mysql_result($Result,$i,"Var"); Is the way im doing this wrong? I would think that the select would pull all the data and the numrows only counts the rows so i can pull the number to use my while statement. I wouldnt think it would affect the formating of my data. But it just returns the values in the standard mysql format with no formatting at all.
ive tried
$Thru=mysql_result($Result,$i,"Thru");
$ThruForm=date(m d Y, $Thru);
and it didnt like that, it did the same thing
so anyone got any ideas?
or should i just rebuild my statement to be mysql_fetch_assoc and do my loop like that?
(that would mean alot of searchin of the internet :P)
Thanks and Help!
Select *, DATE_FORMAT(eFrom , '%m/%d/%Y') as eFrom ...
You say this works on other pages put I'm just wondering if there might be a conflict with using the * in your select statement. I mean you've selected the 'eFrom' column with * and then you're doing it again with the date format. If you don't need to select everything then don't use the *.
As for mysql_fetch_assoc, I'd think that would be a wise investment to get up to speed on that function.
eFrom......eFrom
2004-01-07 01/07/2004
2004-01-07 01/07/2004
So when you use mysql_result($Result,$i, 'eFrom') it is grabbing the first column named eFrom which is unformatted.
Why not use a different alias to prove it?
SELECT *, DATE_FORMAT( `eFrom` , '%m/%d/%Y' ) AS eFromFormatted FROM episodedata
However, for the record, if two or more columns of the result have the same field names, the last column will take precedence, not the first. See mysql_fetch_assoc [php.net] and mysql_fetch_array [php.net] for details.
i did a little foolin round and searchin and couldnt find anything so i decided to figure it out myself again. This time it worked! heres what i came up with...probably not the prettiest thing but it works :)
<?
$Query = "Select *";
$Query = $Query . ", DATE_FORMAT(eFrom , '%m/%d/%Y') as eFrom";
$Query = $Query . ", DATE_FORMAT(Thru , '%m/%d/%Y') as Thru";
$Query = $Query . ", DATE_FORMAT(FirstBillable , '%m/%d/%Y') as FirstBillable";
$Query = $Query . " FROM episodedata WHERE MR = '" . $MR . "' ORDER BY 'eFrom' DESC";
$Result = mysql_query($Query,$Link);
$Num = mysql_numrows($Result);
$Message = "There are $Num episodes for patient $First $Last.";
if ($Num == 0)
{
$Message = "There are no episodes for this patient.";
} else {
$i=0;
while ($Row = mysql_fetch_assoc($Result)) {
if ($i == 0) {
?>
<tr>
<td width="150" class="List"><center><a href="episode_detail.php?EpisodeID=<?= $Row['EpisodeID']?>&MR=<?= $Row['MR']?>"><?= $Row['eFrom']?></a></center></td>
<td width="150" class="List"><center><a href="episode_detail.php?EpisodeID=<?= $ID?>&MR=<?= $MR?>"><?= $Row['Thru']?></a></center></td>
<td width="150" class="List"><center><?= $Row['FirstBillable']?></center></td>
<td width="150" class="List"><center><?= $Row['Status']?></center></td>
</tr>
<?
$i=1;
} else {
?>
<tr>
<td width="150" class="List2"><center><a href="episode_detail.php?EpisodeID=<?= $Row['EpisodeID']?>&MR=<?= $Row['MR']?>"><?= $Row['eFrom']?></a></center></td>
<td width="150" class="List2"><center><a href="episode_detail.php?EpisodeID=<?= $ID?>&MR=<?= $MR?>"><?= $Row['Thru']?></a></center></td>
<td width="150" class="List2"><center><?= $Row['FirstBillable']?></center></td>
<td width="150" class="List2"><center><?= $Row['Status']?></center></td>
</td>
</tr>
<?
$i=0;
}
}
}
?>
The major hurdle i had was that every other line in the background was highlighted in a different color as to seperate the search results...and the only way i knew to loop like that was to use numrows... but this simple and obvious solution evaded me..but everything works great!