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();
?>
lett
March 11, 2017, 10:30pm
2
Do you want to compare or do you want to assign a value here?
I want to show everything from the database that is under that ‘users id’ in the table “owned”
lett
March 11, 2017, 10:35pm
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()
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
lett
March 11, 2017, 10:52pm
6
Have you checked that you didn’t zoom in (reset zoom by pressing CTRL + 0)? Tried different browser?
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
lett
March 11, 2017, 11:50pm
8
Save the php file in UTF-8 format .
update the database column in UTF-8 format and check
lett
March 11, 2017, 11:55pm
9
belder93:
$result->num_rows > 0
Are round brackets missing for num_rows
, i.e. num_rows()
?
lett
March 11, 2017, 11:58pm
10
Are you sure while is the correct construct and not a foreach loop?