通过传递同一参数的多个值来搜索mysql db中的值

rqenqsqc  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(307)

我想从我的网站生成一个特定标准的报告,该网站是一个web应用程序,用于节省故障时间和公司机器的详细信息。在这里,我想根据细分类型、细分机器、细分参与人等生成一个报告。,。
因此,我创建了一个搜索表单来实现这一点,我使用了数据库中的动态下拉菜单,并成功地创建了一个代码,可以选择多个值,比如(在machine下,我们可以选择machine1这样的机器名,machine2等等),在我按search之后,它只显示最后一个选定值的结果,但我想显示所有选定值的结果(详细信息)。


**form.php**

<?php
//index.php
include('database_connection.php');
$country = '';
$query = "
SELECT type FROM reporttype
";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
$country .= '<option value="'.$row["type"].'">'.$row["type"].'</option>';
}
?>
<div class="container">
<h2 align="center"></h2><br /><br />
<form method="post" id="insert_data" action="insert.php">
<label class="col-md-2 bdlabel">Break Down</label>
<select name="country" id="country" class="col-md-10 form-control action">
<option value="">Choose a Category</option>
<?php echo $country; ?>
</select>
<br />
<select name="city" id="city" multiple class="form-control">
</select>
<br />
<input type="hidden" name="hidden_city" id="hidden_city" />
<div class="form-group">
<div class="datepic">
<label class="col-md-2 bdlabel bdfrom">From</label>
<input type="date" name="bdfrom" class="col-md-4">
</div>
<div class="datepic1">
<label class="col-md-2 bdlabel bdto">To</label>
<input type="date" name="bdto" class="col-md-4">
</div>
</div>
<br/>
<input type="submit" name="search" id="action" class="btn btn-info" 
value="Search" />
</form>
</div>
<script>
// JavaScript Document
$(document).ready(function(){
$('#city').lwMultiSelect();
$('.action').change(function(){
if($(this).val() != '')
{
var action = $(this).attr("id");
var query = $(this).val();
var result = '';
if(action == 'country')
{
result = 'city';
}
$.ajax({
url:'fetch.php',
method:"POST",
data:{action:action, query:query},
success:function(data)
{
$('#'+result).html(data);
if(result == 'city')
{
$('#city').data('plugin_lwMultiSelect').updateList();
}
}
})
}
});
});
</script>

插入.php

<?php
//insert.php
include('db.php');
if(isset($_POST['search']))
$city=$_POST['city'];
$from=$_POST['bdfrom'];
$to=$_GET['bdto'];
{
$raw_results = mysql_query("SELECT * FROM breakdownentry
WHERE bdmwc in ('$city') || bdmname in ('$city') || bdaname in ('$city') ") 
or die(mysql_error());         
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following         
while($results = mysql_fetch_array($raw_results)){             
echo "<p>".$results['bdmwc']."</p>";
}
}
else{ 
echo "No results";
}
}
?>

实际形式
我得到的输出
db表值

What i want to show is wire drawing and nail but only nail value is been shown.
pgpifvop

pgpifvop1#

最后找到了答案,我不得不使用内爆函数通过数组得到多个值。在搜索查询中使用内爆函数后,我能够得到多个值并得到我想要的结果。顺便感谢@riggsfully和@olgertelezi的帮助,select标记中的方括号有助于传递数组值。
我已经附上了我的工作代码与此。再次感谢evryone

<?php
                                    //insert.php
                                        include('db.php');
                                        if(isset($_POST['search'])) 
                                            $category=($_POST["country"]);                                  
                                            $machine=($_POST["city"]);
                                            $from=($_POST["bdfrom"]);
                                            $to=($_POST["bdto"]);

                                                $raw_results = mysql_query("SELECT * FROM breakdownentry WHERE ((bddate BETWEEN '$from' AND '$to')) && (bdmname IN ('".implode("','",$machine)."') || bdmwc IN ('".implode("','",$machine)."') || bdaname IN ('".implode("','",$machine)."')) ") or die(mysql_error());

                                                if(mysql_num_rows($raw_results) > 0){
                                    ?>
                                    <div class="widget-content2 resulttable">
                                        <label class="tableheadtb"><?php echo $category.' Break Down details';?></label>
                                        <div class="table-responsive">
                                            <table class="table table-bordered ">
                                                <?php

                                                    // if one or more rows are returned do following
                                                    $limit = 10;  
                                                    if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };  
                                                        $start_from = ($page-1) * $limit;  

                                                        $sql = "SELECT * FROM breakdownentry LIMIT $start_from, $limit";  
                                                        $rs_result = mysql_query ($sql);    
                                                        $a=$start_from + 0;
                                                        $efslno=$start_from + 1354;

                                                ?>

                                                 <thead>
                                                        <tr style="background-color:#FDFE90">
                                                        <th><strong>S.No</strong></th>
                                                        <th><strong>Complaint-Date</strong></th>
                                                        <th><strong>B/D S.No</strong></th>
                                                        <th><strong>Machine ID</strong></th>
                                                        <th><strong>Machine Name</strong></th>
                                                        <th><strong>Work Centre</strong></th>
                                                        <th><strong>B/D ID</strong></th>
                                                        <th><strong>Attended by(ID)</strong></th>
                                                        <th><strong>Attended by Name</strong></th>
                                                        <th><strong>B/D Type</strong></th>                                                  
                                                        <th><strong>B/D Time (Hours)</strong></th>
                                                        <th><strong>B/D Time (Minutes)</strong></th>
                                                        <th><strong>B/D Time (Total)</strong></th>
                                                        <th><strong>B/D Details</strong></th>
                                                        <th><strong>Work Done</strong></th>
                                                        <th><strong>Complaint Status</strong></th>                  
                                                    </tr>
                                                </thead>

                                                <?php   
                                                    while($results = mysql_fetch_array($raw_results)){ 

                                                ?>                                                                                              
                                                <tbody>

                                                    <tr>
                                                        <td><?php echo ++$a;?></td>
                                                        <td><?php echo $results['bddate'];?></td>
                                                        <td><?php 
                                                                $slno = ++$efslno;
                                                                echo $slno;?>
                                                        </td>
                                                        <td><?php echo $results['bdmid'];?></td>
                                                        <td><?php echo $results['bdmname'];?></td>
                                                        <td><?php echo $results['bdmwc'];?></td>
                                                        <td><?php echo $results['bdbdid'];?></td>
                                                        <td><?php echo $results['bdtid'];?></td>
                                                        <td><?php echo $results['bdtname'];?></td>
                                                        <td><?php echo $results['bdbdname'];?></td>                                                         
                                                        <td><?php 
                                                                $bdbreakoccur1=$results['bdbreakreport'];
                                                                $bdamotime1=$results['bdamotime'];
                                                                $time=mysql_fetch_array(mysql_query("SELECT (HOUR (TIMEDIFF ('$bdamotime1','$bdbreakoccur1')))"));                                                              
                                                                echo $time[0] ;
                                                            ?>
                                                        </td>
                                                        <td><?php 
                                                                $bdbreakoccur1=$results['bdbreakreport'];
                                                                $bdamotime1=$results['bdamotime'];
                                                                $time=mysql_fetch_array(mysql_query("SELECT (MINUTE (TIMEDIFF ('$bdamotime1','$bdbreakoccur1')))"));                                                                
                                                                echo $time[0] ;
                                                            ?>
                                                        </td>
                                                        <td><?php 
                                                                $bdbreakoccur1=$results['bdbreakreport'];
                                                                $bdamotime1=$results['bdamotime'];
                                                                $time=mysql_fetch_array(mysql_query("SELECT ((HOUR (TIMEDIFF ('$bdamotime1','$bdbreakoccur1'))*(60)) + (MINUTE (TIMEDIFF('$bdamotime1','$bdbreakoccur1'))))/60"));
                                                                echo $time[0] ;
                                                            ?>
                                                        </td>
                                                        <td><?php echo $results['bdacause'];?></td>                                                         
                                                        <td><?php echo $results['bdawdc'];?></td>
                                                        <td><?php echo $results['bdaradio'];?></td>
                                                    </tr>
                                                </tbody>
                                                <?php           
                                                    }
                                                ?>
                                            </table>
                                        </div>
                                        <?php  
                                            $sql = "SELECT COUNT(id) FROM breakdownentry";  
                                            $rs_result = mysql_query($sql);  
                                            $row = mysql_fetch_row($rs_result);  
                                            $total_records = $row[0];  
                                            $total_pages = ceil($total_records / $limit);  
                                            $pagLink = "<div class='widget-foot'>";  
                                            for ($i=1; $i<=$total_pages; $i++) {  
                                                $pagLink .= "<a href='break-down-list.php?page=".$i."'>".$i."</a>";  
                                                };  
                                            echo $pagLink . "</div>";
                                            }
                                            else{ // if there is no matching rows do following
                                                    echo "<p class='ep'>No Results to Show</p>";
                                            }  
                                        ?>
                                    </div>
xlpyo6sf

xlpyo6sf2#

要在窗体上获取多个值,应添加 [] 在比赛结束时 name 属性
例如:

<select name="city[]" id="city" multiple class="form-control">

相关问题