<?php
//Step1
$db = mysqli_connect('localhost','root','','form')
or die('Error connecting to MySQL server.');
//Step2
$query = "SELECT * FROM info";
mysqli_query($db, $query) or die('Error querying database.');
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
while ($row = mysqli_fetch_array($result)) {
$nam=$row['name'];
$fnam=$row['father'];
$date=$row['date'];
$aadh=$row['aadhaar'];
}
1.In this code it fetches all the values that are stored in the database . But I am in need of the code for fetching the top most row from the database. 2.The query with top attribute is also not working. It gives the following error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1 * FROM info LIMIT 0, 30' at line 1
This is not a PHP issue, it's rather a matter of your MySQL query.
This will return everything because of the * usage.
$query = "SELECT * FROM info";
You can try this instead:
$query = "SELECT *
FROM info
WHERE unique_id = (SELECT MAX(unique_id) FROM info)";