这只是一个例子,我有一个mysql查询,我有一个查询的条件数组。
$b = array(Jan, Feb, March);
$c = array(idle, active);
$hr_ne3 = "SELECT any statement WHERE b = 'Jan' AND c = 'idle'";
$result_hr_ne3 = mysql_query($hr_ne3);
$ne_hr3=mysql_fetch_array($result_hr_ne3,MYSQL_ASSOC);
所以查询的条件将遵循数组。 1月->伊德尔, 二月->伊德尔, 三月-> 然后继续 1 月->活跃、2 月->活跃、3 月->活跃
有人有想法和指南来查询这种流程吗? 表格布局应如下所示
拆分为两个循环
$b = array("Jan", "Feb", "March");
$c = array("idle", "active");
foreach($b as $itemB) {
$hr_ne3 = "SELECT any statement WHERE AND b = '".$itemB."' AND c = '".$c[0]."'";
$result_hr_ne3 = mysql_query($hr_ne3);
$ne_hr3=mysql_fetch_array($result_hr_ne3,MYSQL_ASSOC);
//echo $hr_ne3."n";
}
foreach($b as $itemC) {
$hr_ne3 = "SELECT any statement WHERE AND b = '".$itemC."' AND c = '".$c[1]."'";
$result_hr_ne3 = mysql_query($hr_ne3);
$ne_hr3=mysql_fetch_array($result_hr_ne3,MYSQL_ASSOC);
//echo $hr_ne3."n";
}
如果您取消评论echo
您将获得
SELECT any statement WHERE AND b = 'Jan' AND c = 'idle'
SELECT any statement WHERE AND b = 'Feb' AND c = 'idle'
SELECT any statement WHERE AND b = 'March' AND c = 'idle'
SELECT any statement WHERE AND b = 'Jan' AND c = 'active'
SELECT any statement WHERE AND b = 'Feb' AND c = 'active'
SELECT any statement WHERE AND b = 'March' AND c = 'active'
<?php
$b = array('Jan', 'Feb', 'March');
$c = array('idle', 'active');
$result_array = array();
foreach($c as $key){
foreach ($b as $value) {
$query = "SELECT any statement WHERE b = '".$value."' AND c = '".$key."'";
$result = mysql_query($query);
$result_array[] = mysql_fetch_array($result,MYSQL_ASSOC);
}
echo "<pre/>";print_r($result_array);
}
?>