我有下面的代码将db列数据显示为表标题
$reportID=$_GET["reportID"];
$result=mysql_query("SELECT * FROM reportFields")or die('Could not connect:loggod line 30 iD' . mysql_error());
$num_rows = mysql_num_rows($result);
echo " <tbody> "; // first row beginning
for ($i = 1; $i <= mysql_num_rows($result); $i++)
{
$row = mysql_fetch_array($result);
$field = $row ['field'];
echo "
<th>$field</th>
"; }
if ($i % 4 == 0) {
echo ''; // it's time no move to next row
}
这很好,但是我想知道如何将每个$field作为一个单独的变量?
有人能帮忙吗?
另外,如果这是一个模糊的问题,很抱歉,但我是一个新手,可能试图做一些混乱的事情!
提前谢谢
最佳答案
根据你在评论里写的。。。
$reportID=$_GET["reportID"];
$query = "SELECT * FROM reportFields WHERE reportID=$reportID";
$result=mysql_query($query)or die('Could not connect:loggod line 30 iD' . mysql_error());
$i=1;
echo "<tbody><tr>"; // first row beginning
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$field = $row ['field'];
$reportID = $row ['reportID'];
echo "<td>$reportID</td>";
echo "<td>$field</td>";
if ($i % 4 == 0)echo '</tr><tr>'; // it's time no move to next row
$i++;
}
echo "</tr></tbody>";
关于php - 将列拆分为单独的变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30038430/