Re: getting last entry in database table

From: Date: Sat, 17 Mar 2001 19:12:49 +0000
Subject: Re: getting last entry in database table
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-7567@lists.php.net to get a copy of this message
Do this: $querykb = "SELECT e_description FROM events WHERE t_id = '$t_id' ORDER BY id desc"; where id is the unique id of each row. Then it will order it like: Entry 2 Entry 1 ---- David Balatero ---- Martin Skjöldebrand wrote: > Martin Skjöldebrand wrote: > > > I have a table containing steps toward solving a problem. I want to pass > > the last entry to another database as a solution. > > How do I do this? What I've tried today is: > > I read a few more pages in my newbie book and decided to try it like this > instead: > > > <? if (isset($cmdAddtoKb)) { > $querykb ="SELECT e_description FROM events WHERE t_id = '$t_id';"; > $resultkb = mysql_query($querykb, $mysql_link); > $answer = mysql_fetch_row($resultkb); > foreach ($answer As $teststring) //while we are inside the array > { > $kb_answer = $teststring; //pass the current string to the final > variable > } > > I've got two entries in e_description: > note 1 > note 2 > > Still $kb_answer refuses to become anything other than "note 1". What I'm > looking to do it to get it to be "note 2" or rather the *last* entry in the > table e_description that fits the SELECT statement (there might be 1,2, 7 > or 94 entries. I still want $kb_answer to be the last one). > > Frustrating being a newbie, > > Martin S. > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#7567) next »