Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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 mysql中以正确的方式进行搜索?_Php_Mysql - Fatal编程技术网

显示我已经做了多次搜索如何在php mysql中以正确的方式进行搜索?

显示我已经做了多次搜索如何在php mysql中以正确的方式进行搜索?,php,mysql,Php,Mysql,这是我的表格 <table width="50%" align="center" border="0" class="categorytable" cellpadding="5"> <tr style="background-color:#4390d2;"> <th scope="col" style="color:#FFFFFF; font-weight:bold; text-align:left; padding:5p

这是我的表格

<table width="50%" align="center" border="0" class="categorytable" cellpadding="5">
          <tr style="background-color:#4390d2;">
            <th scope="col" style="color:#FFFFFF; font-weight:bold; text-align:left; padding:5px;">CONSOLIDATED SEARCH</th>
            <th scope="col" style="color:#FFFFFF; font-weight:bold;"><div align="center">&nbsp;</div></th>
          </tr>
          <tr>
            <th style="text-align:left; padding-left:20px;">Academic  Batch</th>
            <th><select name="batchid" class="textbox"  onChange="getState(this.value)">
                <option value="">---Batch---</option>
                <?php
               $sqltype=mysql_query("select * from batch order by batch_id");
               while($row=mysql_fetch_array($sqltype))
               { 
               ?>
                <option value="<?php echo $row['batch_id'] ?>"><?php echo $row['batchname'];?></option>
                <?php 
              }
              ?>
              </select>
            </th>
          </tr>
          <tr>
            <th style="text-align:left; padding-left:20px;">Academic Year</th>
            <th> <div id="statediv">
                <select name="state" class="textbox">
                  <option>Select Batch First</option>
                </select>
              </div>
            </th>
          </tr>
          <tr>
            <th scope="col" style="text-align:left; padding-left:20px;">Department</th>
            <th> <select  class="textbox" name="events_type" id="event_type">
                <option value="">---Category---</option>
                <?php   
                    $sqltype=mysql_query("select * from types order by id desc");
                    while($rowtype=mysql_fetch_assoc($sqltype))
                    {
                ?>
                <option value="<?php echo $rowtype['id'];?>"><?php echo strtoupper($rowtype['name']);?></option>
                <?php
                    }
                ?>
              </select>
            </th>
          </tr>
          <tr>
            <th scope="col" style="text-align:left; padding-left:20px;">Quota</th>
            <th> <select name="quota" class="textbox" >
                <option value="">---Quota---</option>
                <option value="Management" <?php if(isset($quota)){echo "selected";}?>>Management</option>
                <option value="Government" <?php if(isset($quota)){echo "selected";}?>>Government</option>
              </select>
            </th>
          </tr>
          <tr>
            <th scope="col" colspan="2"><input type="submit" name="consol" value="Search" /></th>
          </tr>
        </table>



select 
    b.batchname,
    y.yearname,
    ty.name as major,
    t.*,sum(t.tfeesnow) as tfeesnow1,
    sum(t.efeesnow) as efeesnow1,
    sum(t.bfeesnow) as bfeesnow1,
    sum(t.hfeesnow) as hfeesnow1,
    sum(t.ofeesnow) as ofeesnow1,
    sum(t.totfeesnow) as totfeesnow1 from trans t 
       inner join batch b on batch_id=t.batch 
       inner join year y on y.year_id=t.ayear 
       inner join types ty on ty.id=t.course 
    where batch='1'and ayear='1'and course='1'and quota='Management' group by rollno 
如何纠正此问题。

您可以这样做

$query = "select 
b.batchname,
y.yearname,
ty.name as major,
t.*,sum(t.tfeesnow) as tfeesnow1,
sum(t.efeesnow) as efeesnow1,
sum(t.bfeesnow) as bfeesnow1,
sum(t.hfeesnow) as hfeesnow1,
sum(t.ofeesnow) as ofeesnow1,
sum(t.totfeesnow) as totfeesnow1 from trans t 
   inner join batch b on =t.batch 
   inner join year y on y.year_id=t.ayear 
   inner join types ty on ty.id=t.course 
where batch_id is not null "
//NOTNULL将始终为true将保留where关键字

然后

if (strlen(batch) > 0 )
{
$query= $query . " and batch ='1' ";
}

// this if conditions follow for all codition in query
//lastly 

$query = $query . "group by rollno ";

@Rangarajakrishnan您的评论无法阅读,请在您的问题中编辑它
if (strlen(batch) > 0 )
{
$query= $query . " and batch ='1' ";
}

// this if conditions follow for all codition in query
//lastly 

$query = $query . "group by rollno ";