[英]PHP echo mysql field names in while loop
I am running this Select query:我正在运行这个 Select 查询:
$sql="SELECT * from callplandata group by description ";
$rs=mysql_query($sql,$conn);
while($row = mysql_fetch_row($rs)) {
echo '<tr>';
for($i=0; $i<$fields_num; $i++) {
$field = mysql_fetch_field($rs);
echo '<td>
<input type="text" name="columnname'.$x.'" value="'.$field->name.'" />
<input type="text" name="" value="'.$row[$i].'" />
</td>';
}
echo '</tr>';
}
to display mysql table data and column names.显示mysql表数据和列名。
i use $field->name
to show the column name but it is not showing any column names我使用$field->name
来显示列名,但它没有显示任何列名
Instead of mysql_fetch_row
use mysqli_fetch_assoc
, then just loop over the row:而不是mysql_fetch_row
使用mysqli_fetch_assoc
,然后只需循环该行:
$rs = mysqli_query($sql,$conn);
while ($row = mysql_fetch_assoc($rs)) {
foreach ($row as $column => $value) {
}
}
you need to use the index too你也需要使用索引
echo '<tr>';
for($i=0; $i<$fields_num; $i++) {
$field = mysql_fetch_field($rs,$i);//use the index value here
echo '<td>
<input type="text" name="columnname'.$x.'" value="'.$field->name.'" />
<input type="text" name="" value="'.$row[$i].'" />
</td>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.