Jump to content

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);
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.