Cant figure this out to save my life

php_mysql

#1

this is my code below I can not figure out why its giving me this error:

"Parse error: syntax error, unexpected 'while' (T_WHILE) in D:\xampp\htdocs\test.php on line 8"

this is just a test page I have so I can test errors by themselves.

<?php 
	require('db/db.inc.php');
	
	$sql = "SELECT * FROM owned WHERE user_id = 1";
	$result = $conn->query($sql);
	
	if ($result->num_rows > 0) {
    	   while($row = $result->fetch_assoc()) {
        
    	   }
	} else {
    	   echo "0 results";
	}
	$conn->close();
?>


#2

Do you want to compare or do you want to assign a value here?


#3

I want to show everything from the database that is under that 'users id' in the table "owned"


#4

I wanted to say that the while loop expects a bool value. But what you did was an assignment to the variable $row:
$row = $result->fetch_assoc()

Shouldn't it be something like this instead?

$row == $result->fetch_assoc()


#5

nah I try that to as a last resort and that didn't change it all that error is saying is that while is suppose to be there but in reality it is and I cant figure out why its saying that


#6

Have you checked that you didn't zoom in (reset zoom by pressing CTRL + 0)? Tried different browser?


#7

I have multiple browser on the pc and there all doing the same thing this is just really frustrating because I know I did it right but its saying its wrong


#8

Save the php file in UTF-8 format .

update the database column in UTF-8 format and check


#9

Are round brackets missing for num_rows, i.e. num_rows()?


#10

Are you sure while is the correct construct and not a foreach loop?