Click here to Skip to main content
13,737,156 members
Rate this:
 
Please Sign up or sign in to vote.
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 29-Jan-18 21:37pm
Updated 29-Jan-18 21:55pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 30 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100