Jump to content

Last record inserted in the id=auto_increment


wobbie

Recommended Posts

Hi guys! I trying to get the last record inserted in id_headline and id = auto_increment

With 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 field

Please help.  :o

<?php

mysql_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 id
echo $row[1]; // id_headline
?>
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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.