使用while循环将数据从SQL数据库php dpo显示到html表不起作用 $result=$heidisql->prepare($sql); $result->execute(); 而($users=$result->fetch(PDO::fetch_ASSOC)){ $db_userid=$users[“id”]; $db_user_firstname=$users[“firstname”]; $db_user_lastname=$users[“lastname”]; $db_user_username=$users[“username”]; $db_email_address=$users[“emailaddress”]; $db_postal_address=$users[“postal_address”]; $db_邮政编码=$users[“user_邮政编码”]; $db_gender_id=$users[“gender_id”]; $db_date_of_birth=$users[“date_of_birth”]; $db_telephone=$users[“userlast_login_time”]; $db_activation_account=$users[“act_token_time”]; $db_last_logintime=$users[“userlast_login_time”]; 如果($users>0){ $tfirst=“”; $theadcorfirst=“”; $theadacremiddle=“”; $theadcorlast=“”; $tbodycoreFirst=“”; $tbodycoreMiddle=“”; $tbodycoreLast=“”; $tlast=“”; $HTMLHP_table=$tfirst.$TheADCOMMIRIST。“用户ID”。$TheADCOMMIDLE。“名字”。$TheADCOMMIDLE。“姓氏”。$TheADCOMMIDLE。“用户名”。$TheADCOMMIDLE “电子邮件地址”。$theadcormiddle。“邮政地址”。$theadcormiddle。“邮政编码”。$theadcormiddle “性别”。$theadcormiddle。“出生日期”。$theadcormiddle。“电话号码”。$theadcormiddle “活动帐户时间”。$TheADCOMMIDLE。“上次登录时间”。$TheADCORLAST; //解析结果集,并在HTML表中添加每一行和列 $HTMLPPP\U table.=$tbodycoreFirst.$db\U userid.$TBODYCOREMIDE .$db_user_firstname.$tbodycoreMiddle.$db_user_lastname.$tbodycoreMiddle.$db_user_username.$tbodycoreMiddle .$db_电子邮件地址。$tbodycoreMiddle。$db_邮政地址。$tbodycoreMiddle。$db_邮政编码。$tbodycoreMiddle .$db_性别识别号$tbodycoreMiddle.$db_出生日期$tbodycoreMiddle.$db_电话$tbodycoreMiddle .$db_activation_account.$tbodycoreMiddle.$db_last_logintime.$tbodycoreLast; $HTMLHP_table.=$tlast;//结束HTML表 echo$htmlhp_表; } }
我正在从数据库中获取结果,但结果如下所示 1) 名|姓|用户名|电子邮件地址|邮政地址|用户|邮政编码|性别|身份|出生日期|等使用while循环将数据从SQL数据库php dpo显示到html表不起作用 $result=$heidisql->prepare($sql); $result->execute(); 而($users=$result->fetch(PDO::fetch_ASSOC)){ $db_userid=$users[“id”]; $db_user_firstname=$users[“firstname”]; $db_user_lastname=$users[“lastname”]; $db_user_username=$users[“username”]; $db_email_address=$users[“emailaddress”]; $db_postal_address=$users[“postal_address”]; $db_邮政编码=$users[“user_邮政编码”]; $db_gender_id=$users[“gender_id”]; $db_date_of_birth=$users[“date_of_birth”]; $db_telephone=$users[“userlast_login_time”]; $db_activation_account=$users[“act_token_time”]; $db_last_logintime=$users[“userlast_login_time”]; 如果($users>0){ $tfirst=“”; $theadcorfirst=“”; $theadacremiddle=“”; $theadcorlast=“”; $tbodycoreFirst=“”; $tbodycoreMiddle=“”; $tbodycoreLast=“”; $tlast=“”; $HTMLHP_table=$tfirst.$TheADCOMMIRIST。“用户ID”。$TheADCOMMIDLE。“名字”。$TheADCOMMIDLE。“姓氏”。$TheADCOMMIDLE。“用户名”。$TheADCOMMIDLE “电子邮件地址”。$theadcormiddle。“邮政地址”。$theadcormiddle。“邮政编码”。$theadcormiddle “性别”。$theadcormiddle。“出生日期”。$theadcormiddle。“电话号码”。$theadcormiddle “活动帐户时间”。$TheADCOMMIDLE。“上次登录时间”。$TheADCORLAST; //解析结果集,并在HTML表中添加每一行和列 $HTMLPPP\U table.=$tbodycoreFirst.$db\U userid.$TBODYCOREMIDE .$db_user_firstname.$tbodycoreMiddle.$db_user_lastname.$tbodycoreMiddle.$db_user_username.$tbodycoreMiddle .$db_电子邮件地址。$tbodycoreMiddle。$db_邮政地址。$tbodycoreMiddle。$db_邮政编码。$tbodycoreMiddle .$db_性别识别号$tbodycoreMiddle.$db_出生日期$tbodycoreMiddle.$db_电话$tbodycoreMiddle .$db_activation_account.$tbodycoreMiddle.$db_last_logintime.$tbodycoreLast; $HTMLHP_table.=$tlast;//结束HTML表 echo$htmlhp_表; } },php,mysql,while-loop,Php,Mysql,While Loop,我正在从数据库中获取结果,但结果如下所示 1) 名|姓|用户名|电子邮件地址|邮政地址|用户|邮政编码|性别|身份|出生日期|等 那个么这里只有1行数据 2) 名|姓|用户名|电子邮件地址|邮政地址|用户|邮政编码|性别|身份|出生日期|等 那个么这里只有1行数据 3) 名|姓|用户名|电子邮件地址|邮政地址|用户|邮政编码|性别|身份|出生日期|等 然后这里只有一行数据,以此类推 而不是: 名|姓|用户名|电子邮件地址|邮政地址|用户|邮政编码|性别|身份|出生日期|等 所有行和
- 那个么这里只有1行数据李>
- 那个么这里只有1行数据李>
- 然后这里只有一行数据,以此类推
- 所有行和列数据都应显示在此处
- 哦,还有如何限制要显示的列数(例如,如果我只想显示100个结果中的10个)
$result = $heidisql->prepare($sql);
$result->execute();
while($users = $result->fetch(PDO::FETCH_ASSOC)) {
$db_userid = $users["id"];
$db_user_firstname = $users["firstname"];
$db_user_lastname = $users["lastname"];
$db_user_username = $users ["username"];
$db_email_address = $users["emailaddress"];
$db_postal_address = $users ["postal_address"];
$db_postal_code = $users["user_postal_code"];
$db_gender_id = $users["gender_id"];
$db_date_of_birth = $users["date_of_birth"];
$db_telephone = $users["userlast_login_time"];
$db_activation_account = $users["act_token_time"];
$db_last_logintime = $users["userlast_login_time"];
if ($users > 0) {
$tfirst="<table id='example' class='display table table-striped table-bordered' >";
$theadcoreFirst="<thead><tr><th>";
$theadcoreMiddle="</th><th>";
$theadcoreLast="</th></tr></thead>";
$tbodycoreFirst="<tbody><tr><td>";
$tbodycoreMiddle="</td><td>";
$tbodycoreLast="</td></tr></tbody>";
$tlast="</table>";
$htmlPHP_table = $tfirst. $theadcoreFirst."User ID" .$theadcoreMiddle. "First Name" .$theadcoreMiddle. "Last Name" .$theadcoreMiddle. "User Name" .$theadcoreMiddle
. "Email Address" .$theadcoreMiddle. "Postal Address" .$theadcoreMiddle. "Postal Code" .$theadcoreMiddle
. "Gender" .$theadcoreMiddle. "Date of Birth" .$theadcoreMiddle. "Phone No" .$theadcoreMiddle
. "Active Account Time" .$theadcoreMiddle. "Last Login Time" .$theadcoreLast;
// Parse the result set, and adds each row and colums in HTML table
$htmlPHP_table .= $tbodycoreFirst .$db_userid. $tbodycoreMiddle
.$db_user_firstname .$tbodycoreMiddle. $db_user_lastname .$tbodycoreMiddle. $db_user_username. $tbodycoreMiddle
.$db_email_address .$tbodycoreMiddle. $db_postal_address. $tbodycoreMiddle. $db_postal_code. $tbodycoreMiddle
.$db_gender_id .$tbodycoreMiddle .$db_date_of_birth .$tbodycoreMiddle. $db_telephone. $tbodycoreMiddle
.$db_activation_account .$tbodycoreMiddle. $db_last_logintime .$tbodycoreLast;
$htmlPHP_table .= $tlast; // ends the HTML table
echo $htmlPHP_table;
}
}
$result=$heidisql->prepare($sql);
$result->execute();
如果($users>0){
$tfirst=“”;
$theadcorfirst=“”;
$theadacremiddle=“”;
$theadcorlast=“”;
$tbodycoreFirst=“”;
$tbodycoreMiddle=“”;
$tbodycoreLast=“”;
$tlast=“”;
$HTMLHP_table=$tfirst.$TheADCOMMIRIST。“用户ID”。$TheADCOMMIDLE。“名字”。$TheADCOMMIDLE。“姓氏”。$TheADCOMMIDLE。“用户名”。$TheADCOMMIDLE
“电子邮件地址”。$theadcormiddle。“邮政地址”。$theadcormiddle。“邮政编码”。$theadcormiddle
“性别”。$theadcormiddle。“出生日期”。$theadcormiddle。“电话号码”。$theadcormiddle
“活动帐户时间”。$TheADCOMMIDLE。“上次登录时间”。$TheADCORLAST;
而($users=$result->fetch(PDO::fetch_ASSOC)){
$db_userid=$users[“id”];
$db_user_firstname=$users[“firstname”];
$db_user_lastname=$users[“lastname”];
$db_user_username=$users[“username”];
$db_email_address=$users[“emailaddress”];
$db_postal_address=$users[“postal_address”];
$db_邮政编码=$users[“user_邮政编码”];
$db_gender_id=$users[“gender_id”];
$db_date_of_birth=$users[“date_of_birth”];
$db_telephone=$users[“userlast_login_time”];
$db_activation_account=$users[“act_token_time”];
$db_last_logintime=$users[“userlast_login_time”];
//解析结果集,并在HTML表中添加每一行和列
$HTMLPPP\U table.=$tbodycoreFirst.$db\U userid.$TBODYCOREMIDE
.$db_user_firstname.$tbodycoreMiddle.$db_user_lastname.$tbodycoreMiddle.$db_user_username.$tbodycoreMiddle
.$db_电子邮件地址。$tbodycoreMiddle。$db_邮政地址。$tbodycoreMiddle。$db_邮政编码。$tbodycoreMiddle
.$db_性别识别号$tbodycoreMiddle.$db_出生日期$tbodycoreMiddle.$db_电话$tbodycoreMiddle
.$db_activation_account.$tbodycoreMiddle.$db_last_logintime.$tbodycoreLast;
}
$HTMLHP_table.=$tlast;//结束HTML表
echo$htmlhp_表;
}
您需要在while循环中将表的开头和标题放在外部。只有要迭代的数据才会在while循环中
$result = $heidisql->prepare($sql);
$result->execute();
while($users = $result->fetch(PDO::FETCH_ASSOC)) {
$db_userid = $users["id"];
$db_user_firstname = $users["firstname"];
$db_user_lastname = $users["lastname"];
$db_user_username = $users ["username"];
$db_email_address = $users["emailaddress"];
$db_postal_address = $users ["postal_address"];
$db_postal_code = $users["user_postal_code"];
$db_gender_id = $users["gender_id"];
$db_date_of_birth = $users["date_of_birth"];
$db_telephone = $users["userlast_login_time"];
$db_activation_account = $users["act_token_time"];
$db_last_logintime = $users["userlast_login_time"];
if ($users > 0) {
$tfirst="<table id='example' class='display table table-striped table-bordered' >";
$theadcoreFirst="<thead><tr><th>";
$theadcoreMiddle="</th><th>";
$theadcoreLast="</th></tr></thead>";
$tbodycoreFirst="<tbody><tr><td>";
$tbodycoreMiddle="</td><td>";
$tbodycoreLast="</td></tr></tbody>";
$tlast="</table>";
$htmlPHP_table = $tfirst. $theadcoreFirst."User ID" .$theadcoreMiddle. "First Name" .$theadcoreMiddle. "Last Name" .$theadcoreMiddle. "User Name" .$theadcoreMiddle
. "Email Address" .$theadcoreMiddle. "Postal Address" .$theadcoreMiddle. "Postal Code" .$theadcoreMiddle
. "Gender" .$theadcoreMiddle. "Date of Birth" .$theadcoreMiddle. "Phone No" .$theadcoreMiddle
. "Active Account Time" .$theadcoreMiddle. "Last Login Time" .$theadcoreLast;
// Parse the result set, and adds each row and colums in HTML table
$htmlPHP_table .= $tbodycoreFirst .$db_userid. $tbodycoreMiddle
.$db_user_firstname .$tbodycoreMiddle. $db_user_lastname .$tbodycoreMiddle. $db_user_username. $tbodycoreMiddle
.$db_email_address .$tbodycoreMiddle. $db_postal_address. $tbodycoreMiddle. $db_postal_code. $tbodycoreMiddle
.$db_gender_id .$tbodycoreMiddle .$db_date_of_birth .$tbodycoreMiddle. $db_telephone. $tbodycoreMiddle
.$db_activation_account .$tbodycoreMiddle. $db_last_logintime .$tbodycoreLast;
$htmlPHP_table .= $tlast; // ends the HTML table
echo $htmlPHP_table;
}
}
$result=$heidisql->prepare($sql);
$result->execute();
如果($users>0){
$tfirst=“”;
$theadcorfirst=“”;
$theadacremiddle=“”;
$THADC