tags:

views:

29

answers:

1

Suppose I do a select like this:

select company, location, acnum, bills from table

Just how do i output data using php so that the company and location remain at the top and every bill is printed and the acnum is displayed at the bottom. I'm using mysql_fetch_assoc and have gone mad trying. I can go tru every record but cant get one at the top and bottom.

I'm trying to get data out like this:

 Company name here Location here
 Bill
 Bill
 Bill
 Bill

 Acnum goes here.

P.S I'm new to PHP. I used to program in ASP before.

A: 

If you have the company ID you can do something like this:

    $sql = 'SELECT company, location, acnum 
    FROM Companies
    WHERE id = '.$id

    $result = mysql_query($sql);

    $company = mysql_fetch_assoc($result)) {
    mysql_free_result($result);   

    $sql = 'SELECT bills 
    FROM Companies
    WHERE id = '.$id

    $result = mysql_query($sql);

    while ($row = mysql_fetch_assoc($result)) {
        $bills[] = $row;
    }

    mysql_free_result($result);

    echo $company['company'] . $company['location'];

    foreach($bills as $bill) {
      echo $bill['bills'];
    }

    echo $company['acnum'];
infinity