【发布时间】:2014-07-21 09:49:03
【问题描述】:
我有一个查询函数(下面的代码),我用它来读取数据库,我想知道如何循环打印以输出 -ALL- 结果到一个类似这样的表中:
我用这个得到它:
$visa=$DB->query("SELECT fname,lname,email FROM users");
echo '<table BORDERCOLOR=black>';
?>
<tr>
<th>Name</th><th>LastName</th><th>E-Mail</th>
</tr>
<?php
echo "<td>";
echo $visa[0]['fname'];
echo "</td>";
echo "<td>";
echo $visa[0]['lname'];
echo "</td>";
echo "<td>";
echo $visa[0]['email'];
echo "</td>";
查询功能:
function query($querytext) {
$rs = mysql_query($querytext, $this->_link);
if($this->_debug) {
$this->addDebugMessage("\t<tr>\n\t\t<td class=\"debug_nr\">".$this->_queryCount++."</td>\n\t\t<td class=\"debug_queInfo\"><b>Query: (".@mysql_num_rows($rs).")</b></td>\n\t\t<td>" . htmlspecialchars($querytext) . "</td>\n\t</tr>\n");
if(mysql_error() != '') {
$this->addDebugMessage("\t<tr>\n\t\t<td class=\"debug_nr\">".$this->_queryCount++."</td>\n\t\t<td class=\"debug_queInfo\"><b>Error #".mysql_errno($this->_link)." :</b></td>\n\t\t<td>" . htmlspecialchars(mysql_error($this->_link)) . "</td>\n\t</tr>\n");
}
}
if($rs) {
$num_rows = @mysql_num_rows($rs);
if($num_rows) {
if($num_rows > 0) {
$rsarray = array();
while($line = mysql_fetch_array($rs , MYSQL_ASSOC)) {
array_push($rsarray, $line);
}
mysql_free_result($rs);
return $rsarray;
} else {
return false;
}
} else {
if(mysql_affected_rows($this->_link) > 0) {
return true;
} else {
return false;
}
}
} else {
return false;
}
}
【问题讨论】:
标签: php mysql arrays printing html-table