- Im trying to display a record with a where clause
It has an error "Trying to get property 'num_rows' of non-object"
'<?php' 'require_once "connect.php";' '$sql = "SELECT No,TimeIssued,Type FROM QueueR WHERE Type='Regular'";' '$result = $conn->query($sql);' 'if($result->num_rows > 0){' 'echo "<table class='table table-bordered table-striped'>";' 'echo "<thead>";' 'echo "<tr>";' 'echo "<th>No</th>";' 'echo "<th>TimeIssued</th>";' 'echo "</tr>";' 'echo "</thead>";' 'echo "<tbody>";' 'while($row = $result->fetch_assoc()){' 'echo "<tr>";' 'echo "<td>" . $row['No'] . "</td>";' 'echo "<td>" . $row['TimeIssued'] . "</td>";' 'echo "</tr>";' '}' 'echo "</tbody>";' 'echo "</table>";' '$result->free();' '} else{' 'echo "<p class='lead'><em>No records were found.</em></p>";' '}' '?>'
'''
Asked
Active
Viewed 41 times
0

hajji rs ratunil
- 3
- 4
-
the table should display all records where type is "Regular" – hajji rs ratunil May 05 '20 at 17:56
-
$result is not an object, Check the value of $result after calling query() – Melvyn Marigny May 05 '20 at 17:58
-
what is in your connect.php? – Ibrahim Abou Khalil May 05 '20 at 17:59
-
the error is : Notice: Trying to get property 'num_rows' of non-object in C:\wamp64\www\queue\carmen\display.php on line 44 – hajji rs ratunil May 05 '20 at 18:00
-
line 44 is if($result->num_rows > 0){ – hajji rs ratunil May 05 '20 at 18:01
-
@MelvynMarigny Il try to check the value of $result. Thanks – hajji rs ratunil May 05 '20 at 18:04
-
@Ibrahim my connect.php is ok.. i am sure with this. Thanks – hajji rs ratunil May 05 '20 at 18:05
-
1What are all those apostrophes doing? – Strawberry May 05 '20 at 18:06
-
its not part of the code. sorry. just omit the apostrophes @Strawberry – hajji rs ratunil May 05 '20 at 18:08
-
And note that, while not reserved, `no` is a recognised keyword in MySQL – Strawberry May 05 '20 at 18:09
-
The thing is it is either $conn is not connecting right or the query itself have an issue. Try testing the query a mysql client if fine use include("connect.php") instead of require_once "connect.php". – Ibrahim Abou Khalil May 05 '20 at 18:10
-
@MelvynMarigny can you show me how do I check the value of $result after the calling query – hajji rs ratunil May 05 '20 at 18:12
-
Edit your question accordingly – Strawberry May 05 '20 at 18:13
-
@Ibrahim you did it ibrahim... thanks so much – hajji rs ratunil May 05 '20 at 18:15
-
You are more than welcomed. And feel free to ask me any time. I'll Add my answer so please up-vote it and mark it as a solution. – Ibrahim Abou Khalil May 05 '20 at 18:18
-
thanks so much @melvynmarigny – hajji rs ratunil May 05 '20 at 18:26
-
thanks so much @strawberry – hajji rs ratunil May 05 '20 at 18:26
-
keep safe everyone – hajji rs ratunil May 05 '20 at 18:27
-
how do I up-vote it @Ibrahim – hajji rs ratunil May 05 '20 at 18:28
-
click the up arrow near my comment that helped you fix the issue or just click the up arrow button to the answer I just added below. – Ibrahim Abou Khalil May 05 '20 at 18:31
-
@ibrahim why was it wrong to use require_once? – hajji rs ratunil May 05 '20 at 18:32
-
Check this for detailed explanation https://stackoverflow.com/questions/2418473/difference-between-require-include-require-once-and-include-once – Ibrahim Abou Khalil May 05 '20 at 18:34
1 Answers
0
Check if $conn
in the connect.php is connecting fine.
Try testing the query in a mysql client.
Use include("connect.php")
instead of require_once "connect.php"
.

Ibrahim Abou Khalil
- 312
- 1
- 12
-
can i contact you again if i have riddles to solve? thanks friend. – hajji rs ratunil May 05 '20 at 18:33
-
-
Hi Ibrahim... I want to count all the records with type = 'regular'. I have this code but it lacks the query: $sql = "SELECT Count(*) FROM ViewQueue WHERE Type = 'Regular'"; $result = $conn->query($sql); echo [$result]; – hajji rs ratunil May 08 '20 at 14:56
-
For the query use this :$sql="SELECT COUNT([PrimayKey]) FROM ViewQueue WHERE Type = 'Regular'". And $result is an array use print_r($result) or $result['name of value you want']. – Ibrahim Abou Khalil May 12 '20 at 09:07