我从mysql得到双重输出。我将一个资源用于列,另一个用于行,以及一个 for 循环。
function selectItems($table)
{
$resultado='';
$select_resource = mysql_query("SELECT * FROM ".$table);
$num_rows = mysql_num_fields($select_resource);
for($i=0;$i<$num_rows;$i++){
$result = mysql_fetch_array($select_resource);
foreach($result as $key=>$var)
{
$resultado .="$key: $var<br/>\n";
}
$resultado .="<hr />";
}
return $resultado;
}
这是测试
$data = new Db();
$data->connect(HOST, USER, DB, PASSWORD);
echo $data->selectItems("comments");
$data->closeDb();
这是输出
/*
0: 1
id: 1
1: name
username: name
2: Content
comment: Content
3: 000.000.000.000
ip: 000.000.000.000
4: It’s impressive how popular content management i
title: It’s impressive how popular content management i
5: freemind
avatar: freemind
*/