PHP If statement always returning else condition
PHP If statement always returning else condition
(OP)
Oon my Search page I've got dropdowns that are linked to an SQL database and pull a list of names (e.g. the combination accent northern-brown-male-manchester brings up A & B, southern-grey-female-london brings up X & Y)
This works fine. What I'm trying to do is add an if statement so if no rows are returned, I get a default message of
"No actors match your criteria, please try again"
The problem is, I always get the default message, even when records are being returned
Is it a bracket problem?....It's always a bracket problem!
This works fine. What I'm trying to do is add an if statement so if no rows are returned, I get a default message of
"No actors match your criteria, please try again"
The problem is, I always get the default message, even when records are being returned
CODE --> php
if ($result->num_rows > 0){ echo '<table><tr><th>id</th><th>name</th></tr>'; while($row=$result->fetch()) { echo '<tr><td>'.$row['id'].'</td><td>'.$row['name'].'</td></tr>'; } echo '</table>'; } else { echo '<p> No actors match your criteria, please try again </p>'; }
Is it a bracket problem?....It's always a bracket problem!
RE: PHP If statement always returning else condition
Could you specify what are you using to access the database ?
Feherke.
feherke.github.io
RE: PHP If statement always returning else condition
CODE --> php
Thanks for any help you can give me
RE: PHP If statement always returning else condition
I would suggest to lower the error reporting level on your development machine. You should receive a notice for that code :
As mentioned earlier, PDO's PDOStatement class has no num_rows property.
Feherke.
feherke.github.io
RE: PHP If statement always returning else condition