php - How can I retrieve specific information from my sql query based on what information is filled in the HTML form fields? -


i brand new php , else, please try keep response simple possible. thank you. can't figure out how information field filled in. when search, brings empty fields well. need information in html form found. example, if put in project code, need information pertains code. or if put in specific budget, need has budget. hope makes sense...i'm such rookie, don't know how word question!!!! have tried using !is_null, (isset), !empty none of them seem work.

<?php  include 'connect.php';   // values form  $p_code=$_get['projectcode']; $p_name=$_get['projectname']; $budget=$_get['budget']; $s_date=$_get['startdate']; $e_date=$_get['enddate']; $c_year=$_get['cyear']; $c_qtr=$_get['cqtr']; $c_grp=$_get['cgrp']; $sponsor=$_get['sponsor']; $client=$_get['client']; $p_lead=$_get['projectlead']; $orig_hrs=$_get['originalhrs']; $risk_per=$_get['riskpercent']; $notes=$_get['notes'];  if ($db_found) {    $sql = "select * minimodtable  projectcode='$p_code'  or projectname='$p_name'    or budget='$budget'  or startdate='$s_date'  or enddate='$e_date'  or cyear='$c_year'  or cqtr='$c_qtr'  or cgrp='$c_grp'  or sponsor='$sponsor'  or client='$client'  or projectlead='$p_lead'  or originalhrs='$orig_hrs'  or riskpercent='$risk_per'  or notes='$notes'";  $result = mysqli_query($connect, $sql);  echo "<table border='1'> <tr> <th>project code</th> <th>project name</th> <th>budget</th> <th>start date</th> <th>end date</th> <th>year</th> <th>quarter</th> <th>group</th> <th>sponsor</th> <th>client</th> <th>project lead</th> <th>original hours</th> <th>risk percent</th> <th>notes</th> </tr>";   while ($row = mysqli_fetch_array($result, mysqli_both)) {   echo "<tr>"; echo "<td>" . $row['projectcode'] . "</td>"; echo "<td>" . $row['projectname'] . "</td>"; echo "<td>" . $row['budget'] . "</td>"; echo "<td>" . $row['startdate'] . "</td>"; echo "<td>" . $row['enddate'] . "</td>"; echo "<td>" . $row['cyear'] . "</td>"; echo "<td>" . $row['cqtr'] . "</td>"; echo "<td>" . $row['cgrp'] . "</td>"; echo "<td>" . $row['sponsor'] . "</td>"; echo "<td>" . $row['client'] . "</td>"; echo "<td>" . $row['projectlead'] . "</td>"; echo "<td>" . $row['originalhrs'] . "</td>"; echo "<td>" . $row['riskpercent'] . "</td>"; echo "<td>" . $row['notes'] . "</td>";  }   echo "</table>";    }  mysqli_close($connect);    ?> 

you've made first try there. method should save having repeat much, though. correct start looking @ isset - issue need dynamically build sql query.

in fact, you'll want change glue in implode() function 'or' 'and' - way, can find things specific budget , pertain code.

i've switched and - feel free switch or - per example.

<?php  // possible parameters $params = array(     'projectcode',     'projectname',     'budget',     'startdate',     'enddate',     'cyear',     'cqtr',     'cgrp',     'sponsor',     'client',     'projectlead',     'originalhrs',     'riskpercent',     'notes' );  $wheres = array(); foreach ($params $param) {      // param set?     // if so, let's add our list of clauses     if (isset($_get[$param])) {         $wheres[] = sprintf("%s = '%s'", $param, mysqli_real_escape_string($connect, $_get[$param]));     } }  if ($db_found) {      // let's make sql.     $sql = 'select * minimodtable';      // want add clause if had parameters passed     if (count($wheres) > 0) {         $sql .= ' ' . implode(' , ', $wheres);     }      $result = mysqli_query($connect, $sql);      echo "<table border='1'>     <tr>     <th>project code</th>     <th>project name</th>     <th>budget</th>     <th>start date</th>     <th>end date</th>     <th>year</th>     <th>quarter</th>     <th>group</th>     <th>sponsor</th>     <th>client</th>     <th>project lead</th>     <th>original hours</th>     <th>risk percent</th>     <th>notes</th>     </tr>";      while ($row = mysqli_fetch_array($result, mysqli_both)) {          echo "<tr>";         echo "<td>" . $row['projectcode'] . "</td>";         echo "<td>" . $row['projectname'] . "</td>";         echo "<td>" . $row['budget'] . "</td>";         echo "<td>" . $row['startdate'] . "</td>";         echo "<td>" . $row['enddate'] . "</td>";         echo "<td>" . $row['cyear'] . "</td>";         echo "<td>" . $row['cqtr'] . "</td>";         echo "<td>" . $row['cgrp'] . "</td>";         echo "<td>" . $row['sponsor'] . "</td>";         echo "<td>" . $row['client'] . "</td>";         echo "<td>" . $row['projectlead'] . "</td>";         echo "<td>" . $row['originalhrs'] . "</td>";         echo "<td>" . $row['riskpercent'] . "</td>";         echo "<td>" . $row['notes'] . "</td>";      }      echo "</table>"; }  mysqli_close($connect); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -