Reputation: 345
I am facing a bug I guess, the database records the date format as YYYY-MM-DD, below is the table:-
The 1st table is the funds and the second is the fundshistory, as you can see LibraIncomeExtra Fund has the same date, but it still show stars. Below is my coding:-
<?php
$result = mysql_query("SELECT * FROM funds");
$numrows = mysql_num_rows($result);
$getdate = date('y-m-j');
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>";
echo "<center>";
if ($row['nav'] != $row['oldnav'])
{
if ($row['date_update'] != $getdate)
{
echo "" .$row['fundname']. "**";
$latestupdate = $row['date_update'];
}
}
else
{
echo $row['fundname'];
}
echo "</center>";
echo "</td>";
echo "<td>";
echo"<center>";
echo $row['nav'];
echo "</center>";
echo "</td>";
echo "</tr>";
}
?>
Anyone can explain this? I know mysql extension is decprecated, but this coding was made long time ago, so I don't wish to redo to whole system by just changing mysqli extension.
Upvotes: 1
Views: 160
Reputation: 345
I managed to solve it myself by using this coding:
<?php
$result = mysql_query("SELECT * FROM funds");
$numrows = mysql_num_rows($result);
$getdate = date('Y-m-d');
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>";
echo "<center>";
if ($row['date_update'] == $getdate)
{
echo "" .$row['fundname']. "**";
$latestupdate = $row['date_update'];
}
else
{
echo $row['fundname'];
}
echo "</center>";
echo "</td>";
echo "<td>";
echo"<center>";
echo $row['nav'];
echo "</center>";
echo "</td>";
echo "</tr>";
}
?>
The reason why it shows star is because using while for each line is being checked, as you refer the top previous coding I made, it is satisfy both statement, which require nav and old nav to be different which is true according to the table, next the date from database on table funds and current date on $getdate, which is both are also different that cause both statement to be true and execute the if statement coding. It is kinda stupid for me for not to see the mistake on the if condition. Thanks to firestream for giving that $getdate solution. AND I MADE A MISTAKE, the fundshistory table does not involved in this error.
THIS IS A TRICKY QUESTION :D Cheers!
Upvotes: 0
Reputation: 400
I think your problem is how you declare $getdate
Try this instead: $getdate = date('Y-m-d');
Upvotes: 2