尋求顯示使用PHP存儲在MySQL數據庫中的第一條記錄的'post'字段的值。 以下DIV是其中值是要插入:使用PHP在現有div中顯示MySQL值
<div id="insert1"><?php echo($r); ?></div>
的PHP(注意事項使用MeekroDB):
<?php
require_once 'meekrodb.2.2.class.php';
DB::$user = 'username';
DB::$password = 'password';
DB::$dbName = 'database';
DB::$host = 'hostname';
// get all entries from database table Microblog;
$results = DB::query("SELECT post FROM MicroBlog");
foreach ($results as $row) {
$id = $row['id'];
// loop through each entry - there's 3
for($i = 0; $i < 3; $i++) {
// if it's the 1st entry (id = 1) then get field 'post'
if ($id == 1) {
$r = $row['post'];
}
}
}
?>
目前#insert1是空白。 我需要更改哪些內容才能進入div?請注意,我想保留for循環,因爲一旦我運行它,我將添加其他if。謝謝。
至少增加最基本的錯誤檢查 –