【发布时间】:2014-10-11 12:50:54
【问题描述】:
我正在寻找一种方法来遍历数据库并在 html 页面中显示结果,我实际上是在为一个小项目创建一个假电子邮件系统。
所以我有一个表名“SENDS”,其中包含 5 列 ID、Mailtext、Touser、Subject、Fromuser。 我想做的是当用户登录系统连接到数据库并选择所有内容时 from SENDS where touser='$email' -$email 在用户登录时定义 - 并显示在 html div 中
<div class="oubx">
<div class="inbx">
<span class="from"></span>
<span class="subject"></span>
<span class="mailtext"></span>
</div>
</div>
.oubx {
height:27px; width:800px;
border:1px solid black;
margin-top:;
margin-left:80px;
float:left;
background-color:white;
}
.inbx {
height:22px; width:700px;
border:1px solid black;
margin-top:1px;
margin-left:45px;
background-color:white;
font-family:sans-serif;
font-weight:bold;
font-size:16px;
color:#808080;
float:left;
}
from 当然会告诉它来自谁
主题是主题
mailtext 是邮件的内容(它是隐藏的,当然 jQ 会在点击后处理它)
我使用过 mysqli_num_rows、mysqli_fetch_array、for 循环、foreach 等,但我似乎无法理解它,我很难弄清楚如何逐步设置或步骤是什么。请帮忙 :) 谢谢。
$connectDB = mysqli_connect("host","root","","db");
$touser = mysqli_query($connectDB, "select * from sends where touser='$email'");
$to_numrows = mysqli_num_rows($touser);
$to_fetch = mysqli_fetch_array($touser);
//printing of html code = how many rows
$ib = '<div class="oubx"><div class="inbx"><span class="from">'.$value.'</span><span class="subject">'.$value.'</span></div></div>';
for ($i = 0; $i < $to_numrows; $i++) {
echo $ib;
}
其余的工作正在进行中..
【问题讨论】:
-
嘿嘿!你的服务器端代码在哪里? (用于连接数据库、获取结果的 PHP 代码……)
-
这真的很糟糕,我很惭愧把它放在这里,度过了糟糕的一天