如何逐个回显查询结果?

时间:2011-03-31 02:01:33

标签: php mysql

我的查询是:

$qStuff=mysql_query("SELECT c.field_name,t.category_name, d.domain_name FROM category_fields c, taxonomy_category t, taxonomy_domain d WHERE c.category_id = t.category_id AND t.domain_id = d.domain_id AND c.field_name = '" . mysql_real_escape_string($first_word) . "'");

如何分别回显c.field_name,t.category_name和d.domain_name?

像这样输出

字段名称:

类别名称:

域名:

3 个答案:

答案 0 :(得分:2)

while ($row = mysql_fetch_assoc($qStuff)) {

    echo 'Field name: ' . $row['c.field_name'] . '<br />'; 
    echo 'Category name: ' . $row['t.category_name'] . '<br />'; 
    echo 'Domain name: ' . $row['d.domain_name'] . '<br />'; 

}

答案 1 :(得分:0)

<?php
 $qStuff=mysql_query("SELECT c.field_name,t.category_name, d.domain_name FROM category_fields c, taxonomy_category t, taxonomy_domain d WHERE c.category_id = t.category_id AND t.domain_id = d.domain_id AND c.field_name = '" . mysql_real_escape_string($first_word) . "'");


 $result_array = mysql_fetch_assoc($qStuff);
 echo "Field name: ", $result_array["field_name"], "<br />";
 echo "Category name: ", $result_array["category_name"], "<br />";
 echo "Domain name: ", $result_array["domain_name"], "<br />";
 echo "<br />";
?> 

答案 2 :(得分:0)

<?php

$qStuff = mysql_query("SELECT c.field_name,t.category_name, d.domain_name FROM category_fields c, taxonomy_category t, taxonomy_domain d WHERE c.category_id = t.category_id AND t.domain_id = d.domain_id AND c.field_name = '" . mysql_real_escape_string($first_word) . "'");

while( $row = mysql_fetch_array($qStuff) ){

     echo "Field Name: " . $row['c.field_name'] . "<br />";
     echo "Category Name: ". $row['t.category_name'] . "<br />";
     echo "Domain Name: " . $row['d.domain_name'] . "<br />";
}
?>