问题是陈旧的,但现在可以用mysqli_ *来完成它
//Function to generate a HTML table from a SQL query
function myTable($obConn,$sql)
{
$rsResult = mysqli_query($obConn, $sql) or die(mysqli_error($obConn));
if(mysqli_num_rows($rsResult)>0)
{
//We start with header
echo "
$i = 0;
while ($i < mysqli_num_fields($rsResult)){
$field = mysqli_fetch_field_direct($rsResult, $i);
$fieldName=$field->name;
echo "
$fieldName";$i = $i + 1;
}
echo "
";//We dump info
$bolWhite=true;
while ($row = mysqli_fetch_assoc($rsResult)) {
echo $bolWhite ? "
" : "";$bolWhite=!$bolWhite;
foreach($row as $data) {
echo "
$data";}
echo "
";}
echo "
";}
}