SELECT gives warning

I am getting
Warning : mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\Users\lurtnowski\webserver\htdocs\ICE-v-4.6 -php\san-diego\watch_floor_room_setup.php on line 201
when I run

$sql = "SELECT contents.rack_id,,contents.entity_x_pos, contents.entity_y_pos, contents.entity_width, contents.entity_height, contents.entity_text, contents.entity_secondary_text,
		racks.title
		FROM contents 
		INNER JOIN racks ON racks.rack_id = contents.rack_id 
		WHERE contents.location = 'Watch Floor'";
		
        $result = mysqli_query($conn, $sql);
				 if (mysqli_num_rows($result) > 0) {
								
					while($row = mysqli_fetch_assoc($result)) {
					   ...
                                           ...
					}
					
				 } else {
				  
				  echo "<tr><td colspan='4' style='text-align:center'>0 results</td></tr>";
				 
				 }

but if I run the query through phpmyadmin, it works.

Why the error?

  1. Comma…
SELECT contents.rack_id,,
  1. Are you sure that your connection correct?

There’s your hint.
If your query returns FALSE (boolean), it means the server rejected your query.

        $result = mysqli_query($conn, $sql);
        echo mysqli_error($conn);

pro tip: always test your SQL directly in MySQL before embedding it inside a server language like PHP

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.