我有这个密码:

<?php
$agenti = $_GET['agenti'];
$agen = array();
if (is_array($agenti)) {foreach($agenti as $val) { $agen[] = "ch.employeename LIKE '" . $val . "'"; }} else {$agen[] = 'true';}

    $raw_results = mysql_query("SELECT distinct ch.employeename, ch.customername,
                                       ch.customerowner, ch.QuestionnaireName, ch.parentgroupname,
                                       ch.groupname, ch.visitdate from chestionare ch
                                    WHERE ch.visitdate >= '".$_GET['from']."' AND ch.visitdate <= '".$_GET['to']."'
                                    AND (" . implode(' OR ', $agen) . ")
                                    AND ch.customerowner like '$clienti'
                                    AND ch.class like '$task'
                                    AND ch.parentgroupname like '$categorie'
                                    ")
                                or die(mysql_error());

    if(mysql_num_rows($raw_results) > 0){
        while($results = mysql_fetch_array($raw_results)){ ?>

如果$agenti有多个值(60 values),我该怎么办。值来自另一个<select multiple="multiple"> <option value="test"> test </option>< /select>的文件

最佳答案

如果$agenti是动态数组。简单示例:

$agen = array();

foreach ($agenti as $val) {
    $agen[] = "ch.employeename like '" . $val . "'";
}

$raw_results = mysql_query(
           "SELECT distinct ch.employeename, ch.customername,
               ch.customerowner, ch.QuestionnaireName, ch.parentgroupname,
               ch.groupname, ch.visitdate from chestionare ch
            WHERE ch.visitdate >= '".$_GET['from']."' AND ch.visitdate <= '".$_GET['to']."'
            AND (" . implode(' OR ', $agen) . ")
            AND ch.customerowner like '$clienti'
            AND ch.class like '$task'
            AND ch.parentgroupname like '$categorie'
         ");
or die(mysql_error());

关于php - 像查询mysql php中的多个值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23607986/

10-12 16:03