I am currently trying to display a table using PHP, with the following code:
我目前正在尝试使用PHP显示一个表,其代码如下:
$sqlQ = 'SELECT w_Continent.ID, w_Continent.NAME, w_Country.Name, w_Country.Continent
FROM w_Continent JOIN w_Country
ON w_Continent.ID = w_Country.Continent
;';
$stmtRow = $db->query($sqlQ); //execute sql query
while ($rowOne = $stmtRow->fetchObject()) {
?>
<tr>
<td><?php echo $sqlQ->Name;?></td>
<td><?php echo $sqlQ->Name;?></td>
</tr>
<?php
However, when testing said PHP code, I am receiving an error on the browser which replaces the row of data which should be present, and it reads:
但是,在测试所说的PHP代码时,我在浏览器上收到一个错误,它替换了应该存在的数据行,它显示为:
Notice: Trying to get property of non-object in (directory name)
注意:尝试在(目录名称)中获取非对象的属性
2 个解决方案
#1
2
It should be $rowOne->Name
not $sqlQ->Name
它应该是$ rowOne-> Name而不是$ sqlQ-> Name
$sqlQ
is just a string and doesn't not contain the result from the query
$ sqlQ只是一个字符串,不包含查询结果
#2
0
You are query is failing and returning false which causes the mentioned error
您查询失败并返回false导致提到的错误
$sqlQ = 'SELECT w_Continent.ID, w_Continent.NAME, w_Country.Name, w_Country.Continent FROM w_Continent JOIN w_Country ON w_Continent.ID = w_Country.Continent';
$stmtRow = $db->query($sqlQ); //execute sql query
while ($rowOne = $stmtRow->fetchObject()) {
?>
<tr>
<td><?php echo $rowOne->Name;?></td>
<td><?php echo $rowOne->Name;?></td>
</tr>
<?php
Change the Query to above one and check. Notice semicolon(;) is removed.
将查询更改为上面一个并检查。注意分号(;)被删除。
#1
2
It should be $rowOne->Name
not $sqlQ->Name
它应该是$ rowOne-> Name而不是$ sqlQ-> Name
$sqlQ
is just a string and doesn't not contain the result from the query
$ sqlQ只是一个字符串,不包含查询结果
#2
0
You are query is failing and returning false which causes the mentioned error
您查询失败并返回false导致提到的错误
$sqlQ = 'SELECT w_Continent.ID, w_Continent.NAME, w_Country.Name, w_Country.Continent FROM w_Continent JOIN w_Country ON w_Continent.ID = w_Country.Continent';
$stmtRow = $db->query($sqlQ); //execute sql query
while ($rowOne = $stmtRow->fetchObject()) {
?>
<tr>
<td><?php echo $rowOne->Name;?></td>
<td><?php echo $rowOne->Name;?></td>
</tr>
<?php
Change the Query to above one and check. Notice semicolon(;) is removed.
将查询更改为上面一个并检查。注意分号(;)被删除。