1

I am facing a bug I guess, the database records the date format as YYYY-MM-DD, below is the table:-

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.

9
  • Except I update it with same value of NAV then it the stars in missing else it won't. Commented Sep 11, 2012 at 1:58
  • What happens if you var_dump both of the fields right where you compare them.. I'm begging firestream is right below, needs a capital Y Commented Sep 11, 2012 at 2:40
  • $getdate is set to the current date of the server so date_update will only equal $getdate if the script is run when the server date equals date_update. What are you trying to accomplish with this script? Commented Sep 11, 2012 at 2:49
  • @Stephen WILL try it out later. Commented Sep 11, 2012 at 2:57
  • @JDavis Don't you get it? If the date last update on database and today's date is different then it will echo the fund name with # else just the fund name? Commented Sep 11, 2012 at 2:58

2 Answers 2

2

I think your problem is how you declare $getdate

Try this instead: $getdate = date('Y-m-d');

Sign up to request clarification or add additional context in comments.

2 Comments

Doesn't seems to work. I try putting elseif statement if the date are the same, then echo without stars, still show stars.
@user1631889, i think firestream's advise right. Check return value of php data function, print it out.
0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.