如何打破for循环函数的重复选择查询?

时间:2017-10-29 13:06:24

标签: php

我是初学者php开发人员,我已经为循环函数创建了select select query get id多次相同的id。如何打破多次选择查询获得一个结果?

for ($i = 0; $i < count($_REQUEST['bulk_invoice_group_id']); $i++) {
   $bulk_invoice_id = create_guid();
   $sql = "INSERT INTO ggs_bulk_invoice(id, group_id, service_date, city, service, duration, notes,rate,rate_with_vat, vendor_id,service_meeting_id)"
           . " VALUES('$bulk_invoice_id','{$_REQUEST['bulk_invoice_group_id'][$i]}','{$_REQUEST['bulk_invoice_date'][$i]}','{$_REQUEST['bulk_invoice_city'][$i]}','{$_REQUEST['bulk_invoice_service'][$i]}','{$_REQUEST['bulk_invoice_duration'][$i]}','{$_REQUEST['bulk_invoice_notes'][$i]}' ,'{$_REQUEST['bulk_invoice_rate'][$i]}','{$_REQUEST['bulk_invoice_rate_vat'][$i]}','{$_REQUEST['bulk_invoice_vendor_id'][$i]}','{$_REQUEST['bulk_invoice_meeting_id'][$i]}')";
   $db->query($sql);
   $sql = "INSERT INTO ginvo_client_invoice_ggs_bulk_invoice_1_c(id, ginvo_client_invoice_ggs_bulk_invoice_1ginvo_client_invoice_ida, ginvo_client_invoice_ggs_bulk_invoice_1ggs_bulk_invoice_idb)"
           . " VALUES('" . create_guid() . "','$bean->id','$bulk_invoice_id')";
   $db->query($sql);

   $query = "SELECT DISTINCT id_c, service_type_c FROM meetings_cstm WHERE id_c='".$_REQUEST['bulk_invoice_meeting_id'][$i]."' GROUP BY id_c";

   echo "<pre>";
   print_r($query);
   echo "</pre>";
}

结果

SELECT DISTINCT id_c, service_type_c FROM meetings_cstm WHERE id_c='123' GROUP BY id_c;
SELECT DISTINCT id_c, service_type_c FROM meetings_cstm WHERE id_c='123' GROUP BY id_c;
SELECT DISTINCT id_c, service_type_c FROM meetings_cstm WHERE id_c='123' GROUP BY id_c;
SELECT DISTINCT id_c, service_type_c FROM meetings_cstm WHERE id_c='123' GROUP BY id_c;
SELECT DISTINCT id_c, service_type_c FROM meetings_cstm WHERE id_c='123' GROUP BY id_c;

1 个答案:

答案 0 :(得分:0)

也许你想确保数组元素在循环之前是唯一的

A Unix timestamp