Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello Guys, I want to know how to select top 1 value in MySQL order by Desc please see my code am getting error and I cannot get values please help me thanks

What I have tried:

<?php
if($_SERVER['REQUEST_METHOD']=='POST'){

include 'DatabaseConfig.php';

 $con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);




 $CheckSQL = "SELECT * FROM table ORDER BY rank DESC LIMIT 10";
 
 $check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
 if(isset($check)){
 echo 'Error';
//$Sql_Query = "INSERT INTO users (id) values ('$F_name'+$check)";
 }
else{ 
$Sql_Query = "INSERT INTO complain (complainno) values ('$check')";

 if(mysqli_query($con,$Sql_Query))
{
 echo 'Registration Successfully';
}
else
{
 echo 'Something went wrong';
 }
 }
}
 mysqli_close($con);
?>
Posted
Updated 29-Jan-18 21:55pm

1 solution

If you need just a single row, why don't you use LIMIT 1 in your query?
By the way, your query looks correct, however you failed to report here the exact error message as well the table structure.
 
Share this answer
 
Comments
Member 9983063 30-Jan-18 4:01am    
sir i am not getting any value it's a error
Richard Deeming 30-Jan-18 11:09am    
You still haven't told us what the error message says.
Jörgen Andersson 31-Jan-18 1:55am    
I suspect it is 'Something went wrong'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900