public function Read($Table, $Fields, $Where, $OrderBy, $Limit) {
if ($this->TableExists($Table)) {
$Query = "SELECT " . $Fields . " FROM " . "$Table";
if ($Where != "") {
$Query .= " WHERE " . $Where;
}
if ($OrderBy != "") {
$Query .= " ORDER BY" . $OrderBy;
}
if ($Limit != "") {
$Query .= " LIMIT " . $Limit;
}
$Result = mysql_query($Query);
$Records = mysql_fetch_assoc($Result);
//Extracting the field names
$Keys = array_keys($Records);
$this->Keys = $Keys;
//Extracting recordset
while($Values = array_values($Records)){
$this->Values = $Values;
}
return $this->Values;
return $this->Keys;
}
else {
echo "This table doesn't exists!";
}
} // End Read();
?>
<table>
<tr>
<?php
foreach ($Object->Keys as $Key) {
?>
<th><?php echo $Key; ?></th>
<?php
}
?>
</tr>
// Here i want the database record to be displayed.
</table>
实际上我试图创建一个通用类来获取结果。目标是让 php 代码摆脱 html 元素。我已经成功完成了显示array_keys。我在循环中犯了一些错误,我认为为了显示 array_values 我希望将记录显示在表中请帮助我实现这一点。