我的數(shù)據(jù)庫(kù)中有一個(gè)表attendants和一個(gè)頁(yè)面,results.php該頁(yè)面將包含所有返回行的數(shù)據(jù)。本質(zhì)上我正在嘗試做兩件事:獲取表中的行數(shù)。對(duì)于表中的每一行,將其數(shù)據(jù)輸入到.card但是,在注釋掉幾行之后,我發(fā)現(xiàn)這一行在我的頁(yè)面上導(dǎo)致了嚴(yán)重錯(cuò)誤:$results = $wpdb->get_results("SELECT * FROM attendants");不確定為什么?我認(rèn)為這是 get_results() 函數(shù),但根據(jù)文檔,這似乎是檢索行的正確方法?我也不認(rèn)為正在檢索數(shù)據(jù),因?yàn)楫?dāng)試圖回顯一個(gè)值時(shí),它什么都不返回。結(jié)果.php<?phpglobal $wpdb;$results = $wpdb->get_results("SELECT * FROM attendants");$number_of_results = mysqli_num_rows($results);echo $results; // returns "Array"?><div class="resultsPage"> <div class="card"> <div class="card__header"> <!-- trying to print number of rows in attendants table --> <!-- i.e there are 7 rows in this table, so $number_of_results should return 7 --> <h4>Total respondants: <?php echo $number_of_results; ?></h4> </div> </div> <?php foreach($results as $result){ $first_name = $result["first_name"]; $last_name = $result["last_name"];?> <div class="card"> <div class="card__copy"> <p><span class="card__data">Full name:</span> <?php echo $first_name+" "+$last_name; ?></p> </div> </div> <?php } ?></div>
使用 $wpdb 從 WordPress 中的數(shù)據(jù)庫(kù)獲取行會(huì)導(dǎo)致嚴(yán)重錯(cuò)誤
慕的地8271018
2023-04-15 14:14:23