Click here to Skip to main content
13,831,901 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:


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));
 echo 'Error';
//$Sql_Query = "INSERT INTO users (id) values ('$F_name'+$check)";
$Sql_Query = "INSERT INTO complain (complainno) values ('$check')";

 echo 'Registration Successfully';
 echo 'Something went wrong';
Updated 29-Jan-18 22:55pm

1 solution

Rate this: bad
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.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

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

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