I have a bit of a problem.. kind of!
I have a table with several columns, of course, and most of them are searchable. Basically what I did, was if you entered any text, it would search all the items in the table and return everything. So If I searched for Jessica, I would get Jessica under Staff, possible Jessica under Group, etc etc.
But what I want is to also be able to type, GEP Jessica, and for groups that ONLY contain both keywords to be shown.
Here is my code:
Expand|Select|Wrap|Line Numbers
- <?php
- include ('config.php');
- $keywords = $_REQUEST['search'];
- $words = explode(" ", $keywords);
- foreach ($words as $word) {
- if (isset($where)) {
- $where .= " OR ";
- }
- $where .= "group_name LIKE '%$word%' OR group_start_mm LIKE '%$word%' OR group_destination LIKE '%$word%' OR group_type LIKE '%$word%' OR group_lead LIKE '%$word%' OR group_status LIKE '%$word%' OR staff_user LIKE '%$word%' OR client_name LIKE '%$word%'";
- }
- $vyear = "06";
- $result = mysql_query("SELECT * FROM group06
- left join clients on group06.client_id = clients.client_id
- left join staff on group06.staff_id = staff.staff_id
- WHERE $where")
- or die(mysql_error());
- $num_rows06 = mysql_num_rows($result);
- if (!empty($num_rows06)) {
- while($row = mysql_fetch_array( $result )) {
- ?>
- <div class="view">
- <table width="100%">
- <tr><th colspan="7" align="center"><b>2006</b></th><td align="center"><b>Results: <?php echo $num_rows06; ?></b></td></tr>
- <tr bgcolor=#E5F0FF>
- <td align="center"><b>File #</b></td>
- <td align="center"><b>Client Name</b></td>
- <td align="center"><b>Group Name</b></td>
- <td align="center"><b>Destination</b></td>
- <td align="center"><b>Dates</b></td>
- <td align="center"><b>Staff</b></td>
- <td align="center"><b>Status</b></td>
- <td align="center"><b>Lead</b></td>
- </tr>
- <?php
- while ($row = mysql_fetch_array($result))
- {
- extract($row);
- if ($row['group_id'] > 99) {
- $file_number = $vyear.$row['group_id'];
- } elseif ($row['group_id'] > 9) {
- $file_number = $vyear.'0'.$row['group_id'];
- } else {
- $file_number = $vyear.'00'.$row['group_id'];
- }
- $id=$row['group_id'];
- $contents_here = "
- <td><a href=view_individual.php?database=$vyear&id=$id>".$file_number."</a></td>
- <td style=padding-left:3px;padding-right:3px>".$row['client_name']."</td>
- <td style=padding-left:3px;padding-right:3px>".$row['group_name']."</td>
- <td style=padding-left:3px;padding-right:3px>".$row['group_destination']."</td>
- <td style=padding-left:3px;padding-right:3px>".$row['group_start_mm']."</td>
- <td style=padding-left:3px;padding-right:3px>".$row['staff_user']."</td>
- <td style=padding-left:3px;padding-right:3px>".$row['group_status']."</td>
- <td style=padding-left:3px;padding-right:3px>".$row['group_lead']."</td>";
- if ($i==0)
- {
- echo '<tr>'.$contents_here.'</tr>';
- }
- else
- {
- echo '<tr bgcolor="#F0F0F0">'.$contents_here.'</tr>';
- }
- $i++; $i=$i%2;
- }
- ?>
- </table>
- </div>
- <?php
- }
- }
- ?>