Rogue3 Posted July 6, 2006 Share Posted July 6, 2006 I made a form so that I can add entries into my database, and I need help tweaking the end result a bit. Everything works just fine, the only part I can't figure out is when I enter an item in the database and click my submit button, the page that comes up shows all entries in the database. I'd like it to only show the one I JUST put in (for verification purposes). Here is my code:[code]mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM mytable";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();echo "<b><center>JTA Database Entry</center></b><br><br>";$i=0;while ($i < $num) {$series=mysql_result($result,$i,"series");$type=mysql_result($result,$i,"type");$mfg=mysql_result($result,$i,"mfg");$year=mysql_result($result,$i,"year");$name=mysql_result($result,$i,"name");$link=mysql_result($result,$i,"link");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13838-database-entry-form/ Share on other sites More sharing options...
hussain Posted July 6, 2006 Share Posted July 6, 2006 give limit in query Quote Link to comment https://forums.phpfreaks.com/topic/13838-database-entry-form/#findComment-53821 Share on other sites More sharing options...
Rogue3 Posted July 6, 2006 Author Share Posted July 6, 2006 I added LIMIT to my query. I now get 1 result, however it is the first result in my table. How do I make it show the one I just entered? Here is what I changed:[code]$query="SELECT * FROM guides LIMIT 1";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13838-database-entry-form/#findComment-53833 Share on other sites More sharing options...
Rogue3 Posted July 6, 2006 Author Share Posted July 6, 2006 OK, after fiddling around I think I solved it. Since I have my auto-incriment set for the id I just added this along with the LIMIT 1:ORDER BY id DESC Quote Link to comment https://forums.phpfreaks.com/topic/13838-database-entry-form/#findComment-53839 Share on other sites More sharing options...
fenway Posted July 6, 2006 Share Posted July 6, 2006 Alernatively, you can pull the specific record using LAST_INSERT_ID(). Quote Link to comment https://forums.phpfreaks.com/topic/13838-database-entry-form/#findComment-53959 Share on other sites More sharing options...
Rogue3 Posted July 6, 2006 Author Share Posted July 6, 2006 Hey, that's even better. I don't know how my id's would get out of order, but at least this way it is definately going to pull what I just entered. Quote Link to comment https://forums.phpfreaks.com/topic/13838-database-entry-form/#findComment-53967 Share on other sites More sharing options...
fenway Posted July 6, 2006 Share Posted July 6, 2006 It has nothing to do with IDs being out of order... it's just that there's no need to bother if all you want is the most recently inserted record. Quote Link to comment https://forums.phpfreaks.com/topic/13838-database-entry-form/#findComment-53998 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.