PHP Echo多选查询

时间:2014-06-29 12:09:36

标签: php mysql

我通常使用以下方式将echo用于以下查询

$select_time = mysql_query("SELECT submit_time FROM `table` WHERE field_name='user-email' and field_value='test'");
$fetch_time = mysql_fetch_array($select_time);
echo $fetch_time['submit_time'];

可以,任何人都告诉我如何回应以下场景中的每个值

$select_brands = mysql_query("SELECT max(if(`field_name`='brand-name', `field_value`, null )) AS 'brand-name', max(if(`field_name`='brand-email', `field_value`, null )) AS 'brand-email', max(if(`field_name`='brand-phone', `field_value`, null )) AS 'brand-phone', max(if(`field_name`='brand-manager', `field_value`, null )) AS 'brand-manager' FROM `wp_cf7dbplugin_submits` WHERE `form_name` = 'Add brands' GROUP BY `submit_time` ORDER BY `submit_time` DESC LIMIT 0,100");
$fetch_branddetails = mysql_fetch_array($select_brands);

我需要回应品牌,品牌电子邮件,品牌经理和品牌电话,但坚持使用语法如何为此编写echo语句。

2 个答案:

答案 0 :(得分:2)

您需要for个周期,因为您选择了多行

for ($i = 0; $i < count ($fetch_branddetails); $i ++) { // because you select with LIMIT 0,100 so its max 100 rows
    echo $fetch_branddetails['brand-name'] . $fetch_branddetails['brand-email'] . $fetch_branddetails['brand-manager'] . $fetch_branddetails['brand-phone'] . "\n";
}

将php字符串与.连接起来。新行<{1}}

或仅使用printf "\n";

答案 1 :(得分:1)

非常简单

$fetch_branddetails['brand-name'] 

$fetch_branddetails[0]

品牌名称与其他列相同