【发布时间】:2017-12-19 12:22:08
【问题描述】:
$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;
}
}
我正在从我的数据库中获取结果,但它们看起来像这样
1)名字|姓氏|用户名|电子邮件地址|邮政地址|用户邮政编码|性别ID|出生日期|等等。
- 那么这里只有1行数据!
2)名字|姓氏|用户名|电子邮件地址|邮政地址|用户邮政编码|性别ID|出生日期|等等。
- 那么这里只有1行数据!
3)名字|姓氏|用户名|电子邮件地址|邮政地址|用户邮政编码|性别ID|出生日期|等等。
- 那么这里只有1行数据,等等
代替:
名字|姓氏|用户名|电子邮件地址|邮政地址|用户邮政编码|性别ID|出生日期|等
所有 ROWS 和 Columns 数据都应该出现在这里!?
哦,还有如何限制要显示的列数(例如,如果我只想显示 100 个结果中的 10 个)?
【问题讨论】:
-
好吧,我唯一能说的就是在循环上方创建
table和thead,并在循环内部输出rows.. -
你能举出更多细节的例子吗?你的意思是我把 $htmlPHP_table = $tfirst 放在了 while 循环之上吗?所以我也应该把 theadcoreFirst 分解成两部分 和
? 表格和标题必须在循环之外@JohnLaimuin 在下面试试我的答案
标签: php mysql while-loop