Warning** : mysqli_num_rows(


#1

Warning : mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in

Warning : mysqli_query() expects parameter 1 to be mysqli, string given in

$conn= mysqli_connect("localhost","root",""); 
	if(mysqli_connect_error()) { 
		die('Could not connect: ' . mysqli_connect_error());
	}
	$conn->select_db('); 
 
$search_exploded = explode (" ", $search);
    
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="keywords LIKE '%$search_each%'";
else
$construct .="AND keywords LIKE '%$search_each%'";
   
}
  
$constructs ="SELECT * FROM search WHERE $construct";
$run = mysqli_query($constructs,$webdes42_search);
    
$foundnum = mysqli_num_rows($run);
    
if ($foundnum==0)
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1. 
Try more general words. for example: If you want to search 'how to create a website'
then use general keyword like 'create' 'website'</br>2. Try different words with similar
 meaning</br>3. Please check your spelling";
else
{ 

i need help


#2

Have you tried echoing $constructs to see if it is what you expect before executing the query?


#3

getting this SELECT * FROM search WHERE keywords LIKE '%Created%'AND keywords LIKE '%by%'AND keywords LIKE '%Kenneth%'AND keywords LIKE ‘%Johnson%’


#4

I’m not sure if it’s the problem, but I can see missing spaces before the ANDs.


#5

i need this code in mysqli


#6

What happens when you add the missing spaces?


#7

nothing


#8

That look right to you?


#9

Or what about this?

$run = mysqli_query($constructs,$webdes42_search);
   

I don’t do mysqli, but a quick look at the doc shows that the first parameter is not the query string, hence the second error message in the original post. The first error message comes from not checking whether or not the query executed before trying to use the results.

Not sure what’s in $webdes42_search, whether that might cause a further problem.

I presume the select_db() thing is a typo when anonymising the code for the forum.


#10

that is db name


#11

The database name is '? I am not trying to make fun of you. I’m just trying to figure out why your code looks weird.


#12

A single apostrophe isn’t going to work

https://dev.mysql.com/doc/refman/8.0/en/identifiers.html

Permitted characters in unquoted identifiers:

  • ASCII: [0-9,a-z,A-Z$_] (basic Latin letters, digits 0-9, dollar, underscore)