第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在不聲明列名的情況下回顯 mysqli 結(jié)果中的行?

在不聲明列名的情況下回顯 mysqli 結(jié)果中的行?

PHP
縹緲止盈 2021-10-22 12:54:15
如何在不聲明每個(gè)列名的情況下回顯查詢結(jié)果中的所有行(作為 JSON)?即沒(méi)有寫(xiě)作'location_id' => $row['location_id']等等,就像我在下面所做的那樣。<?phprequire_once("./config.php"); //database configuration filerequire_once("./database.php");//database class file$location_id = isset($_GET["location_id"]) ? $_GET["location_id"] : '';$db = new Database();if (isset($_GET["location_id"])){    $sql = "SELECT * FROM location WHERE location_id = $location_id";} else {    $sql = "SELECT * FROM location";}$results = $db->conn->query($sql);if($results->num_rows > 0){    $data = array();    while($row = $results->fetch_assoc()) {        $data[] = array(        'location_id' => $row['location_id'],        'customer_id' => $row['customer_id'],        'location_id' => $row['location_id'],        'location_name' => $row['location_name'],        'payment_interval' => $row['payment_interval'],        'location_length' => $row['location_length'],        'location_start_date' => $row['location_start_date'],        'location_end_date' => $row['location_end_date'],        'location_status' => $row['location_status'],        'sign_sides' => $row['sign_sides'],        'variable_annual_price' => $row['variable_annual_price'],        'fixed_annual_price' => $row['fixed_annual_price'],        'location_file' => $row['location_file']);    }header("Content-Type: application/json; charset=UTF-8");echo json_encode(array('success' => 1, 'result' => $data));} else {    echo "Records not found.";}?>更新代碼。現(xiàn)在使用@Dharman 推薦的參數(shù)化準(zhǔn)備語(yǔ)句(謝謝?。?。我Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR)在第 17 行。我正在運(yùn)行 PHP 7.3 版。怎么了?我應(yīng)該如何回顯 $data 以便它像以前一樣是 JSON 對(duì)象?<?phpheader("Content-Type: application/json; charset=UTF-8");//include required files in the scriptrequire_once("./config.php"); //database configuration filerequire_once("./database.php");//database class file$object_contract_id = isset($_POST["object_contract_id"]) ? $_POST["object_contract_id"] : '';//create the database connection$db = new Database();
查看完整描述

1 回答

?
拉風(fēng)的咖菲貓

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊

fetch_assoc() 已經(jīng)將您的數(shù)據(jù)作為關(guān)聯(lián)數(shù)組返回,因此您不需要重新進(jìn)行關(guān)聯(lián)。

您可以簡(jiǎn)單地將結(jié)果分配給您的數(shù)據(jù)。=>$data[] = $row

有關(guān)如何fetch_assoc()工作的詳細(xì)說(shuō)明。這是文檔。


查看完整回答
反對(duì) 回復(fù) 2021-10-22
  • 1 回答
  • 0 關(guān)注
  • 130 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)