我正试图从数据库中获取此信息:
$query = "SELECT * FROM station_control WHERE station_no > 0 ORDER BY station_ord";
然后说它期望这两行中的参数:
$station_result= mysqli_query($query);
$num= mysqli_fetch_array($station_result);
这就是我要输出的内容,基本上是从名为station_ord的数据库中提取每个站名,名称在station_name下:
$i=0;while ($i < $num) {
$station_name1=mysqli_result($station_result,$i,"station1_name");
$station2_name= mysqli_result($station_result, $i,"station2_name");
$station3_name= mysqli_result($station_result, $i,"station3_name");
$station4_name= mysqli_result($station_result, $i,"station4_name");
$station5_name= mysqli_result($station_result, $i,"station5_name");
echo "<b>
$station1_name $station2_name2</b> <br>
$station3_name<br>
$station1_name4_name<br>
$station5_name<hr> <br>";
$i++;
}
我还没有放入station_name,因为我很困惑我在哪里以及如何配置它。 任何想法如何帮助?
答案 0 :(得分:0)
这样的事情应该有效。
$station_result= mysqli_query($query);
$results= mysqli_fetch_array($station_result);
foreach ($results as $row) {
// echo whatever you want here
echo $row['station_name'];
}
答案 1 :(得分:0)
不确定您尝试做什么,但请尝试
<?php
$station_result= mysqli_query($query);
$records = mysqli_fetch_array($station_result);
foreach ($records as $record) :?>
<b><?php echo $record['station_name']; ?></b><br/>
<?php endforeach; ?>
参考:http://ch1.php.net/manual/en/mysqli.query.php 和http://www.php.net/manual/en/mysqli-result.fetch-array.php示例