Search code examples
phpmysqlrowsdisplayobject

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. Each row is a different account. So, how could I take the content of the fields and display them like this:

  • Account one: PJ1
  • Account one: PJ2
  • Account one: PJ3...

and NOT like this:

  • Account one: PJ1
  • Account two: PJ1
  • Account three: PJ1...

Here's the structure of the table.

enter image description here

Thank you very much.


Solution

  • 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;
        }
    }