title: PHP PDO CRUD display data based on select box value
body: <p>i was doing practice of PHP PDO CRUD example of codingcage ...link is <a href="http://www.codingcage.com/2015/04/php-pdo-crud-tutorial-using-oop-with.html" rel="nofollow noreferrer">http://www.codingcage.com/2015/04/php-pdo-crud-tutorial-using-oop-with.html</a>
  -- in index.php i have created a select box with dynamic value :</p>
  
  <pre><code>$conn = new mysqli('localhost', 'root', '', 'kk') or die ('Cannot connect to db');
  
  $result = $conn-&gt;query("SELECT DISTINCT project FROM tbl_activitymaster where ProjectFlag='open' ");
  
  echo "&lt;html&gt;";
  echo "&lt;body&gt;";
  echo "&lt;select name='unqprj'&gt;";
  
  while ($row = $result-&gt;fetch_assoc()) {
  
                unset($project, $project);
                $project = $row['project'];
                $name = $row['project']; 
                echo '&lt;option value="'.$project.'"&gt;'.$project.'&lt;/option&gt;';
                $value="&lt;?php echo $project;?&gt;";
               }
  
  echo "&lt;/select&gt;";
  echo "&lt;/body&gt;";
  echo "&lt;/html&gt;";
  </code></pre>
  
  <p>But the problem is that how to use this select box in the crud example to filter the records based on the value selected . I have done it in asp.net but in php how to do this. any help please or any link</p>
  
  <hr>
  
  <pre><code>// as mulder is suggesting but no idea how to implement with this eaample
  &lt;form action='&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;' method='post'  name='form2' &gt;
  &lt;select name="value"&gt;
  &lt;option value="all"&gt;All&lt;/option&gt;
  &lt;option value="Project1"&gt;Project1&lt;/option&gt;
  &lt;option value="Project2"&gt;Project2&lt;/option&gt;
  &lt;/select&gt;   
  &lt;input type='submit' value = 'Show'&gt;
  &lt;/form&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>class.crud.php..............
  //show
  public function dataview($query)
  {
  $stmt = $this-&gt;db-&gt;prepare($query);
  $stmt-&gt;execute();
  if($stmt-&gt;rowCount()&gt;0)
  {
  while($row=$stmt-&gt;fetch(PDO::FETCH_ASSOC))
  {
  ?&gt;
  &lt;td&gt;&lt;?php print($row['id']); ?&gt;&lt;/td&gt;        
  &lt;td&gt;&lt;?php print($row['Project']);?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php print($row['ProjectUser']);?&gt;&lt;/td&gt;                
  &lt;td&gt;&lt;?php print($row['Month']);?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php print($row['Status']);?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php
  }
  }
  else
  {
  ?&gt;
  &lt;tr&gt;
  &lt;td&gt;Nothing here...&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php
  }
  }
  
  
  //paging    
      public function paging($query,$records_per_page)
      {
      $starting_position=0;
      if(isset($_GET["page_no"]))
      {
      $starting_position=($_GET["page_no"]-1)*$records_per_page;
      }
      $query2=$query." limit $starting_position,$records_per_page";
      return $query2;
      }
  </code></pre>
  
  <hr>
  
  <pre><code>index.php...............
  &lt;?php include_once '../header.php'; ?&gt;
  &lt;?php include_once 'dbconfig.php'; ?&gt;
  &lt;?php
  $conn = new mysqli('localhost', 'root', '', 'kk') 
  or die ('Cannot connect to db');
  $result = $conn-&gt;query("SELECT DISTINCT project FROM tbl_activitymaster where ProjectFlag='open' ");
  echo "&lt;html&gt;";
  echo "&lt;body&gt;";
  echo "&lt;select name='unqprj'&gt;";
  while ($row = $result-&gt;fetch_assoc()) {
  unset($project, $project);
  $project = $row['project'];
  $name = $row['project']; 
  echo '&lt;option value="'.$project.'"&gt;'.$project.'&lt;/option&gt;';
  $value="&lt;?php echo $project;?&gt;";
  echo "&lt;/select&gt;";
  echo "&lt;/body&gt;";
  echo "&lt;/html&gt;";
  ?&gt;
  &lt;div class="container"&gt;
  &lt;table class='table table-bordered table-hover table-responsive'&gt;
  &lt;thead style="background-color:#FFFBF0"&gt;
  &lt;tr&gt;
  &lt;th&gt;ID&lt;/th&gt;
  &lt;th&gt;Project&lt;/th&gt;
  &lt;th&gt;ProjectUser&lt;/th&gt;
  &lt;th&gt;Month&lt;/th&gt;
  &lt;th&gt;Status&lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;?php
  $query = "SELECT * FROM tbl_activitymaster where ProjectUser='" . ($_SESSION['sess_username']) . "' ";       
  $records_per_page=10;
  $newquery = $crud-&gt;paging($query,$records_per_page);
  $crud-&gt;dataview($newquery);
  ?&gt;
  &lt;tr&gt;
  &lt;td colspan="7" align="center"&gt;
  &lt;div class="pagination-wrap"&gt;
  &lt;?php $crud-&gt;paginglink($query,$records_per_page); ?&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;?php include_once '../footer.php'; ?&gt;
  </code></pre>