php - call function from multiple options -


i using php call database print 3 different dropdown menus. works. problem calling function , passing dropdown selections function , displaying records after submit button pressed. function build query taking account if 1 of dropwdowns selected or 3.

the function in same page the form.

here form:

 <form action="edit.php" method="post">  <select>       <?php $getgroup = mysql_query("select distinct resgroup restable order               resgroup");        while($viewallgroups = mysql_fetch_array($getgroup)){       ?>       <option id="<?php echo $viewallgroups['resgroup']; ?>"><?php echo $viewallgroups['resgroup']; ?></option><?php } ?>  </select>   <select>       <?php $gettype = mysql_query("select distinct restype restable order restype");       while($viewalltypes = mysql_fetch_array($gettype)){       ?>       <option id="<?php echo $viewalltypes['restype']; ?>"><?php echo $viewalltypes['restype']; ?></option><?php } ?>  </select>   <select>      <?php $getservice = mysql_query("select distinct service restable order service");   while($viewallservices = mysql_fetch_array($getservice)){   ?>       <option id="<?php echo $viewallservices['service']; ?>"><?php echo $viewallservices['service']; ?></option><?php } ?>  </select>  <input type="submit" class="btn btn-primary" value="filter" />  </form> 

here function:

 <?php  function displayrecords(){      $groups = $_post['resgroup'];      $type = $_post['restype'];      $service = $_post['service'];   if($groups != ""){      $where[] = " `resgroup` = '".mysql_real_escape_string($group)."'";  }  if($type != ""){      $where[] = " `restype` = '".mysql_real_escape_string($type)."'";  }  if($service != ""){      $where[] = " `service` = '".mysql_real_escape_string($service)."'";  }   $sql_json = "select * mytable $where_clause order id desc";  }  ?> 

then try display function.

 <?php displayrecords(); ?> 

i not getting error, however, once submit button clicked, dropdown menu's clear out, , doesn't return anything. know i'm missing lot. appreciate help.

thank in advance.

first of please provide name each select element. again in the edit.php file access values of post array name.

now giving example it.

html part:

<select name='select1' >   <option value='1'>value</option>   <option value='1'>value</option> </select> 

now in edit.php can access value of selected element of selectbox select1 $_post['select1'];


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -