Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 仅将选定值传递给使用数组的函数_Php_Mysql_Arrays - Fatal编程技术网

Php 仅将选定值传递给使用数组的函数

Php 仅将选定值传递给使用数组的函数,php,mysql,arrays,Php,Mysql,Arrays,我有一个函数,它接受我想要分解并传递到where条件的数组。 我的职能 <?php function somearray($value = array()) { $conditions = ""; foreach($value as $key => $condition) { $conditions .= "$key=$condition && "; } $conditions = substr($conditi

我有一个函数,它接受我想要分解并传递到where条件的数组。 我的职能

<?php
function somearray($value = array())
{
    $conditions = "";
    foreach($value as $key => $condition)
    {
        $conditions .= "$key=$condition && ";
    }
    $conditions = substr($conditions, 0, -4);
    $qry = mysql_query("SELECT * FROM maincase WHERE $conditions");
    while($arr = mysql_fetch_array($qry))
    {
        echo 'Ticket Number= '.$arr['ticket_number'].'<br />';
    }
}

我想通过表单发送值,但只发送选中的复选框

<?php 
        if(isset($_GET['filter']))
        {
            $list = array(
                "region" => $_GET['region'],
                "status" => $_GET['status']
            );
            somearray($list);
        }
    ?>

    <form action="" class="form-inline" method="get">
        <label for="">Region</label>
        <input type="checkbox" name="region" <?php if(isset($_GET['region'])) { echo 'checked' ;} ?> value="1">

        <label for="">Status</label>
        <input type="checkbox" name="status" <?php if(isset($_GET['status'])) { echo 'checked' ;} ?> value="3">

        <input type="submit" value="filter" name="filter">
    </form>

区域
value=“3”>

这个代码有效。但我必须过滤7到8个字段。我只想在选中复选框的情况下发送值。

在函数中传递值应如下所示:

function somearray($value)
{
    $conditions = "";
    foreach($value as $key => $condition)
    {
        $conditions .= "$key=$condition && ";
    }
    $conditions = substr($conditions, 0, -4);
    $qry = mysql_query("SELECT * FROM maincase WHERE $conditions");
    while($arr = mysql_fetch_array($qry))
    {
        echo 'Ticket Number= '.$arr['ticket_number'].'<br />';
    }
}
?>
函数somearray($value)
{
$conditions=“”;
foreach($key=>$condition的值)
{
$conditions.=“$key=$condition&&”;
}
$conditions=substr($conditions,0,-4);
$qry=mysql_查询(“从maincase中选择*,其中$conditions”);
而($arr=mysql\u fetch\u数组($qry))
{
回音“票号=”。$arr[“票号”]。
; } } ?>
在您的情况下,参数被初始化为默认数组或空数组,当您传递一个带值的数组时

见参考资料:


    • 默认情况下不应发送未选中的复选框



      这段代码显示,只发送所选复选框的数据。

      我从Laravel那里学到了这一点。但这不是问题所在。如果我选中这两个字段,我想发送“region”=>$\u GET['region'],“status”=>$\u GET['status']如果我选中status“status”=>$\u GET['status']等等..你有你公司的数据吗?
      <form action="?" method="post">
          <input type="checkbox" name="first" />
          <input type="checkbox" name="second" />
          <input type="submit" name="OK" />
      </form>
      <?php
          var_dump($_POST);
      
      array(2) { 'first' => string(2) "on" 'OK' => string(6) "Submit" }