Php 打印下面的单个字段

Php 打印下面的单个字段,php,mysql,Php,Mysql,假设我进行如下选择: Company name here Location here Bill Bill Bill Bill Acnum goes here. $sql = 'SELECT company, location, acnum FROM Companies WHERE id = '.$id $result = mysql_query($sql); $company = mysql_fetch_assoc($result))

假设我进行如下选择:

 Company name here Location here
 Bill
 Bill
 Bill
 Bill

 Acnum goes here.
    $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'];
从表中选择公司、地点、金额、账单

如何使用php输出数据,使公司和地点保持在顶部,打印每个账单,并在底部显示acnum。我正在使用mysql_fetch_assoc,并且已经疯狂尝试了。我可以翻出每一张唱片,但不能做到最好和最差

我试图像这样获取数据:

 Company name here Location here
 Bill
 Bill
 Bill
 Bill

 Acnum goes here.
    $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'];

另外,我对PHP还不熟悉。我以前用ASP编程。

如果你有公司ID,你可以这样做:

 Company name here Location here
 Bill
 Bill
 Bill
 Bill

 Acnum goes here.
    $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'];

我不明白你的问题是关于什么的-如何查询结果集,或者如何设置HTML输出的样式?如何查询结果集。我可以使用while循环打印所有数据。但我要按照上面的方式来做。