Jump to content


Photo

PHP won't display newest value from mysql database


  • Please log in to reply
2 replies to this topic

#1 rich_greeny

rich_greeny
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 May 2006 - 04:28 PM

Hi all, i'm new to php and mysql, but starting to get the hang of it with my comp sci student housemate. I'm trying to return values inserted via a text box, but the top entry in the database won't display. If you add another to the database, then it appears, anyone have any ideas, or code to resolve the issue?

Cheers

Rich

[blockquote]$sql = "SELECT * FROM $table_name ORDER BY 'date' DESC";
$result = mysql_query($sql,$connection) or die("Couldn't execute SELECT query");
$row = mysql_fetch_array($result);
while ($row = mysql_fetch_array($result)){
echo "<tr>
<td style=\"width: 87px;\" height=\"0\"> </td>
<td>$row[notice]
</td>
</tr>";
}
mysql_close();
?>[/blockquote]


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 19 May 2006 - 04:46 PM

Remove this line:
<?php $row = mysql_fetch_array($result); ?>
You are getting the first line, not doing anything with it and then getting all the others. Once you remove that line you will be getting all the lines.

Ken

#3 rich_greeny

rich_greeny
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 May 2006 - 04:52 PM

wooo, thanks a bunch. I've done small amounts of programming, but the whole 'not defining the variables' kind of threw me!

Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users