[英]PHP PDO $row inside php code not running
我有問題,我用$ row [name]在我的數據庫中存儲了一條消息。
Helloo $row['name'] how are you
$txt[1] is "Helloo $row['name'] how are you "
這是我嘗試的第一個回顯有效的代碼,但第二個不起作用
<?php
$check = $db->prepare("SELECT * FROM appointments WHERE trimis='0'");
$check->execute();
$checkdb = $check -> fetchAll();
foreach($checkdb as $row){
echo $row['name']; // THIS WORKS
$check = $db->prepare("SELECT * FROM settings WHERE id='1'");
$check->execute();
$checkdb2 = $check -> fetchAll();
foreach($checkdb2 as $txt){
echo $txt[1]."<BR>"; // THIS DOESEN'T
}
}
?>
編寫查詢時,應從表中選擇特定字段,因為使用通配符SELECT *
+按索引訪問行(例如$txt[1]
是解決錯誤的方法:
$check1 = $db->prepare("SELECT name FROM appointments WHERE trimis='0'");
$check1->execute();
while($rows1 = $check1->fetch()){
echo $row['name'];
$check2 = $db->prepare("SELECT custom_text FROM settings WHERE id='1'");
$check2->execute();
while($rows2 = $check2->fetch()){
echo $rows2['custom_text']."<BR>";
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.