1

您好,我正在检查表中的重复数据。我有一个问题是从哪里选择数据。我的代码是:

$sub_cat = array(); 
$select = array("core_network","daisy_chain", "rf_bts", "rf_power", "rf_transmission");
$d='0';
for ($i=0;$i<=4;$i++){
    $SQL = "SELECT sub_cat FROM (".$select[$i].") WHERE location=('".$id."')";
    $result = mysql_query($SQL);

    $cs=$d;

    if ($result) {
        while ($db_field = mysql_fetch_array($result)) {
            if(!in_array($db_field['sub_cat'],$sub_cat)) {
                $sub_cat[]= $db_field['sub_cat'];
                $cs++;
                $d=$cs;
                $d--;
            }
        }
    } 

我需要知道sub_cat从哪个中选择的$select[i]。如何找到它?

4

1 回答 1

1

要获取值,请执行以下操作:

$sub_cat = array(); 
$select = array("core_network","daisy_chain", "rf_bts", "rf_power", "rf_transmission");
$d='0';
for ($i=0;$i<=4;$i++){
    $SQL = "SELECT sub_cat FROM (" . $select[$i] . ") WHERE location=('".$id."')";
    $result = mysql_query($SQL); // deprecated - use PDO

    $cs = $d;

    if ($result) {
        while ($db_field = mysql_fetch_array($result)) {
            if(!in_array($db_field['sub_cat'], $sub_cat)) {
                $table = $select[$i];
                $sub_cat[$table][] = $db_field['sub_cat'];

                // I have no clue what's going on here in your example:
                $cs++;
                $d=$cs;
                $d--;
            }
        }
    } 
}

然后,检索它:

foreach ($sub_cat as $table_name => $values) {
    foreach ($values as $row) {
        // output values here
    }
}
于 2012-12-09T03:48:37.590 回答