ShanesProjects Posted October 19, 2006 Share Posted October 19, 2006 What do I do to my code to make it show the last one row entered?[code]<?include("MySQL_Info.php");$sql="SELECT * FROM users ORDER BY id DESC"; $mysql_result=mysql_query($sql);$num_rows=mysql_num_rows($mysql_result);while ($row=mysql_fetch_array($mysql_result)){$Username=$row["Username"];$Title=$row["Title"];}echo "<center><font color='#C0C0C0'>-Newest User-</font><br /><a href='View_Profile.php?Username=$Username'>$Username</a><br /><font color='Black'>$Title</font></center>";?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/24465-mysql-problem-2/ Share on other sites More sharing options...
ShanesProjects Posted October 19, 2006 Author Share Posted October 19, 2006 Fixed it had to be ORDER BY id ACS. Not ORDER BY id DESC. Quote Link to comment https://forums.phpfreaks.com/topic/24465-mysql-problem-2/#findComment-111458 Share on other sites More sharing options...
HuggieBear Posted October 19, 2006 Share Posted October 19, 2006 That's not correct. If you have an auto incrementing ID then the highest one will be the most recent. I'd use the following code to get the data...[code]<?phpinclude("MySQL_Info.php");// Query selects the last user added to the database and only returns one row$sql = "SELECT * FROM users ORDER BY id DESC LIMIT 1";// I've changed $mysql_result to $result as there's a function called mysql_result() wouldn't want it getting confusing$result = mysql_query($sql) or die ("Couldn't execute:<br>\n$sql<br>\n". mysql_error());$row = mysql_fetch_array($result, MYSQL_ASSOC));//echo the codeecho "<center><font color='#C0C0C0'>-Newest User-</font><br /><a href='View_Profile.php?Username={$row['Username']}'>{$row['Username']}</a><br /><font color='Black'>$Title</font></center>";?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24465-mysql-problem-2/#findComment-111486 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.