Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys i want to select values and show in textbox but i am getting on my edittext on button click
here is the error
<br /> Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /h7/ae/public_html/fashion360/Com.php on line 11<br /> []

please help me please tell me whats the matter and how can i resolved this error
thanks

What I have tried:

<?php
include 'Db.php';
$con=mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName)or die("Cannot Connect");
mysqli_select_db($con,$DatabaseName)or die("Cannot select db");
mysqli_set_charset($con,'utf8');
$sql = "SELECT TOP 1 complainno FROM complain";
$result  =mysqli_query($con,$sql);
$json = array();
if(mysqli_num_rows($result)){
while ($row=mysqli_fetch_assoc($result)){
$json['complainno'][]=$row;
}
}
mysqli_close($con);
echo json_encode($json);
?>
Posted
Updated 31-Jan-18 2:35am
Comments
David Crow 31-Jan-18 9:21am    
The error seems to be strictly PHP related. You might consider removing the Android and Java tags.

1 solution

Your PHP: mysqli::query - Manual[^] call failed:
Quote:

Return Values

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
It is always a good idea to check return values and display error messages upon errors to know what went wrong:
PHP
if ($result = mysqli_query($con,$sql)) {
    // Query was successful: Move on
}
else {
    printf("Error: %s\n", mysqli_error($con));
}

In your case it is probably a syntax error in the query string. As far as I know, MySQL does not know the TOP command. You have to use LIMIT instead:
PHP
$sql = "SELECT complainno FROM complain LIMIT 1";
 
Share this answer
 
Comments
Member 9983063 31-Jan-18 14:37pm    
Hello thanks for your help am trying your query now and am getting error also
i am using now
<?php
include 'DatabaseConfig.php';
$con=mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName)or die("Cannot Connect");
mysqli_select_db($con,$DatabaseName)or die("Cannot select db");
mysqli_set_charset($con,'utf8');
$sql = "SELECT complainno FROM complain LIMIT 1";
$result =mysqli_query($con,$sql);
$json = array();
if(mysqli_num_rows($result)){
while ($row=mysqli_fetch_assoc($result)){
$json['complainno'][]=$row;
}
}
mysqli_close($con);
echo json_encode($json);
?>
please see the error in this screen shot
https://imgur.com/a/QlhoV
Jochen Arndt 1-Feb-18 2:59am    
The mysqli_query() call is still failing. Please use also the error reporting code from my solution. It gives you more information.

Note also that using mysqli_num_rows() makes no sense when the query is limited to return only one row.
Member 9983063 1-Feb-18 3:03am    
so how can i resolve it
Jochen Arndt 1-Feb-18 3:16am    
You have to pass a valid SQL command as query string.

But I don't have your database and can't therefore reproduce it. The first step is - as already suggested - getting the error message from the database interface by calling mysqli_error($con).
Member 9983063 1-Feb-18 4:08am    
well sir my errors are resolved thanks for your help and sir just one thing when i select value with order by table name Desc so it's select asc values but i want Desc values

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