[英]Mysql and PHP select and display columns
There's the problem. 有问题。 I need to display the fields of PJ1 to PJ8 but just the same row. 我需要显示PJ1到PJ8的字段,但只显示同一行。 Each row is a different account. 每行是一个不同的帐户。 So, how could I take the content of the fields and display them like this: 因此,我该如何获取字段的内容并像这样显示它们:
and NOT like this: 而不是这样的:
Here's the structure of the table. 这是表格的结构。
Thank you very much. 非常感谢你。
You need to iterate through each field in the row/record, rather than just iterating through each row in the result. 您需要遍历行/记录中的每个字段,而不仅仅是遍历结果中的每一行。
So you have something along the lines of: 因此,您可以按照以下方式进行操作:
while ($row = mysql_fetch_row($query_result)) {
echo $row[0];
}
But what you really want is: 但是您真正想要的是:
while ($row = mysql_fetch_row($query_result)) {
foreach ($row as $field) {
echo $field;
}
}
Use UNION
使用UNION
SELECT * FROM (
SELECT account_num, PJ1
FROM table
UNION
SELECT account_num, PJ2
FROM table
UNION
SELECT account_num, PJ3
FROM table
...
)
ORDER BY account_num
$query="SELECT * FROM table ";
$result=mysql_query($query);
$i=0;
while($row=mysql_fetch_assoc($result)
{
echo "account no :-"."$i"."$row['pj1']"."</br>";//you can add more column
$i++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.