php - Trouble searching multiple columns in a table using different different POST variables in SQL ILIKE search -


i created form search fields. search fields using query db ilike in statement. works when search 1 variable.

but problem if try adding more variables search wrong output.

the form:

<form action="index.php" method='post' name="form_submit">     <table class='table table-hover table-responsive table-bordered'>         <tr>             <td>name</td>             <td><input type='text' name='searchname' value='' class='form-control' /></td>             <td>email</td>             <td><input type='text' name='searchemail' value='' class='form-control'></td>         </tr>         <tr>             <td>surname</td>             <td><input type='text' name='searchsurname' value='' class='form-control' /></td>             <td>cell</td>             <td><input type='text' name='searchcell' value='' class='form-control'></td>         </tr>         <tr>             <td>id number</td>             <td><input type='text' name='searchid' value='' class='form-control' /></td>             <td>work</td>             <td><input type='text' name='searchwork' value='' class='form-control'></td>         </tr>         <tr>             <td>ref number</td>             <td><input type='text' name='searchref' value='' class='form-control' /></td>             <td>home</td>             <td><input type='text' name='searchhome' value='' class='form-control'></td>         <tr>             <td></td>             <td><input type="text" name="searchphrase" class='form-control' placeholder="search keyword" value=""></td>             <td></td>             <td>                 <button type="submit" name="submit" value="submit" class="btn btn-primary">search</button>             </td>         </tr>     </table> </form> 

the submit:

if(isset($_post['submit']))   {      $ref = $_post['searchref'];     $name = $_post['searchname'];     $surname = $_post['searchsurname'];     $id = $_post['searchid'];      $email = $_post['searchemail'];     $cell = $_post['searchcell'];     $work = $_post['searchwork'];     $home = $_post['searchhome'];      $q = $_post['searchphrase']; 

my sql query:

   //read table      $sqlr =<<<eof       select *        leadgen."tblsearch" t             t."firstname" ilike '%$q%'       or t."refno" ilike '%$q%'        or t."surname" ilike '%$q%'        or t."worktel" ilike '%$q%'       or t."hometel" ilike '%$q%'        or t."celltel" ilike '%$q%'        or t."email" ilike '%$q%'        or t."address" ilike '%$q%'        or t."idnumber" ilike '%$q%'       order t."appdate" desc       limit 20    ; eof; 

lastly output:

 //store query   $retr = pg_query($connection, $sqlr);    //test query    if(!$retr){       echo pg_last_error($connection);       exit;    }       $count = pg_num_rows($retr);    if($count == 0){     echo "<div class='container'>";     echo "there no results, please try again";     echo "</div>";    }else{     //add bootstrap love    echo "<div class= container>";    echo "<h1>results: </h1><br><hr>"; ?>  <table class='table table-hover table-responsive table-bordered'>         <thead>         <tr>             <th>personal details</th>             <th>lead gen</th>             <th>sales company</th>             <th>sales details</th>         </tr>         </thead>  <?php   //echo "<table class='table table-hover table-responsive table-bordered'>";    //loop through data      while($row = pg_fetch_row($retr)){        echo"<div class='bg-success'>";       //echo "tblid = ". $row[0] . "<br>";       echo "<tr>";       echo "<td>";       echo "<div class='text-danger'>refno  = ". $row[1] ."</div>";       echo "title  = ". $row[2] ."<br>";       echo "<span style='font-weight:bold;'>firstname  = ". $row[3] ."</span><br>";       echo "<span style='font-weight:bold;'>surname  = ". $row[4] ."</span><br>";       echo "<a href='#'>worktel =  ".$row[5] ."</a><br>";       echo "hometel =  ".$row[6] ."<br>";       echo "celltel  =  ".$row[7] ."<br>";       echo "email  =  ".$row[8] ."<br>";       echo "address =  ".$row[9] ."<br>";       echo "idnumber =  ".$row[10] ."<br>";       echo "dateofbirth =  ".$row[11] ."<br>";       echo "</td>";       echo "<td>";        echo "</td>";       echo "<td>";        echo "</td>";       echo "<td>";        echo "</tr>";    }        echo "</div>"; echo "</table>"; } 


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -