我正在使用以下代码。
<?php
//DB CONNECTION
$ROWS = "id,firstname,lastname";
// explode at the comma and insert into an array
$test = explode("," , $ROWS);
//adds array test to the var sam
$sam = array($test);
// querys the database
$new = mysql_query("SELECT * FROM {$DB_TABLE}");
// while loop to loop through selected fields
while ($row = mysql_fetch_array($new)) {
foreach ($sam[0] as $v) {
echo $row[$v] . $DELIMITER . "<br />";
}
}
?>
我得到以下结果。
834(|)
Steph(|)
Thompson(|)
835(|)
Lucy(|)
kim(|)
836(|)
Iwan(|)
Will(|)
837(|)
Sarah (|)
Good(|)
我遇到的问题是<br>
标记。我把它放在哪里?因为我需要它像这样输出(就像它显示在$ROWS = "id,firstname,lastname";
上方的$ ROWS变量中)
834(|)Step(|)Thompson(|)
835(|)Lucy(|)kim(|)
836(|)Iwan(|)Will(|)
837(|)Sarah (|)Good(|)
我在哪里添加<br>
代码?
答案 0 :(得分:3)
TRY
while ($row = mysql_fetch_array($new)) {
foreach ($sam[0] as $v) {
echo $row[$v] . $DELIMITER;
}
echo "<br />";
}