wobbie Posted January 30, 2007 Share Posted January 30, 2007 Hi guys! I trying to get the last record inserted in id_headline and id = auto_incrementWith the following code I can get only the record assigned in id '1' ”); and I would like to get the higher no. in the id fieldPlease help. :o<?phpmysql_connect("localhost", "root", "");mysql_select_db( 'hillh' );$result = mysql_query("SELECT id,id_headline FROM admin WHERE id '1'");if (!$result) { echo 'Could not run query: ' . mysql_error(); exit;}$row = mysql_fetch_row($result);echo $row[0]; // value of idecho $row[1]; // id_headline?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 30, 2007 Share Posted January 30, 2007 After your insert, do $id = mysql_insert_id();To get the most recent id at a later time, "SELECT * FROM admin ORDER BY id DESC LIMIT 1" Quote Link to comment Share on other sites More sharing options...
wobbie Posted January 30, 2007 Author Share Posted January 30, 2007 Sorry I do not understand.Do you mean after:$row = mysql_fetch_row($result); ??? Quote Link to comment Share on other sites More sharing options...
wobbie Posted January 30, 2007 Author Share Posted January 30, 2007 Thanks, I've got it. ;D<? require ('class_pagina.php'); require ('class_contenido.php'); $conn = mysql_connect("localhost", "root", "");$sql = mysql_select_db( 'hillh' );$sql2 = "SELECT * FROM admin ORDER BY id DESC LIMIT 1";$result = mysql_query($sql2);$found=0; while($regset=mysql_fetch_object($result)) { $id = $regset->id; //$id_headline = $regset->id_headline; $id_headline = $regset->id_headline; $date = $regset->date; if(!$found) { $found=1; echo "<table border=0 align=\"center\"width='400'><tr class=style1><td><b><font color='#800080'>Results found:</font></td></tr>"; } echo "<tr><td><b>$id</b></td><td>$id_headline</td><td>$date</td></tr>"; } if($found) echo "</table>"; else echo "<h2>Sorry! There are no registers found.<h2>"; mysql_free_result($result); mysql_close($conn); Quote Link to comment 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.