There's the problem. I need to display the fields of PJ1 to PJ8 but just the same row. 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
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++;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.