473,395 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Filter / Sort MySQL results!

Yika
1
Hello all! :)

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
  1. <?php
  2. include ('config.php');
  3.  
  4. $keywords = $_REQUEST['search'];
  5.  
  6. $words = explode(" ", $keywords);
  7. foreach ($words as $word) {
  8. if (isset($where)) {
  9. $where .= " OR ";
  10. }
  11. $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%'";
  12. }
  13.  
  14. $vyear = "06";
  15.  
  16. $result = mysql_query("SELECT * FROM group06
  17. left join clients on group06.client_id = clients.client_id
  18. left join staff on group06.staff_id = staff.staff_id
  19. WHERE $where") 
  20. or die(mysql_error());  
  21.  
  22. $num_rows06 = mysql_num_rows($result); 
  23.  
  24.  
  25. if (!empty($num_rows06)) {
  26.  
  27. while($row = mysql_fetch_array( $result )) {
  28. ?>
  29.  
  30. <div class="view">
  31. <table width="100%">
  32. <tr><th colspan="7" align="center"><b>2006</b></th><td align="center"><b>Results: <?php echo $num_rows06; ?></b></td></tr>
  33.  
  34. <tr bgcolor=#E5F0FF>
  35. <td align="center"><b>File #</b></td>
  36. <td align="center"><b>Client Name</b></td>
  37. <td align="center"><b>Group Name</b></td>
  38. <td align="center"><b>Destination</b></td>
  39. <td align="center"><b>Dates</b></td>
  40. <td align="center"><b>Staff</b></td>
  41. <td align="center"><b>Status</b></td>
  42. <td align="center"><b>Lead</b></td>
  43. </tr>
  44.  
  45. <?php
  46. while ($row = mysql_fetch_array($result))
  47. {
  48. extract($row);
  49. if ($row['group_id'] > 99) {
  50. $file_number = $vyear.$row['group_id'];
  51. } elseif ($row['group_id'] > 9) {
  52. $file_number = $vyear.'0'.$row['group_id'];
  53. } else {
  54. $file_number = $vyear.'00'.$row['group_id'];
  55. }
  56.  
  57. $id=$row['group_id'];
  58.  
  59. $contents_here = "
  60. <td><a href=view_individual.php?database=$vyear&id=$id>".$file_number."</a></td>
  61. <td style=padding-left:3px;padding-right:3px>".$row['client_name']."</td>
  62. <td style=padding-left:3px;padding-right:3px>".$row['group_name']."</td>
  63. <td style=padding-left:3px;padding-right:3px>".$row['group_destination']."</td>
  64. <td style=padding-left:3px;padding-right:3px>".$row['group_start_mm']."</td>
  65. <td style=padding-left:3px;padding-right:3px>".$row['staff_user']."</td>
  66. <td style=padding-left:3px;padding-right:3px>".$row['group_status']."</td>
  67. <td style=padding-left:3px;padding-right:3px>".$row['group_lead']."</td>";
  68.  
  69. if ($i==0)
  70. {
  71. echo '<tr>'.$contents_here.'</tr>';
  72. }
  73.  
  74. else
  75. {
  76. echo '<tr bgcolor="#F0F0F0">'.$contents_here.'</tr>';
  77. }
  78.  
  79.  
  80. $i++; $i=$i%2;
  81. }
  82. ?>
  83.  
  84.  
  85. </table>
  86. </div>
  87.  
  88. <?php
  89. }
  90. ?>
  91.  
So If anyone can help me go in the right direction, MUCH Appreciated!
Nov 29 '06 #1
0 5626

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Phil Powell | last post by:
http://www.php.net/array_filter I went there at first for my information on filtering mySQL query results using PHP, to no avail. This is more of a Vignette construct (my native environment)...
11
by: Matt | last post by:
Hi everyone, still pretty new to MySQL. I was wondering if there is a way to automatically filter records based on a mysql userlogin name?? I have serveral databases that I want to combine in...
0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
8
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and...
2
by: Mike Sweetman | last post by:
I have a form Form1 which when the Advanced Filter/Sort is used creates a form(maybe) with a title 'Form1Filter1 : Filter'. When I apply the filter to Form1 it is applied, but the value of...
4
by: Nhmiller | last post by:
This is directly from Access' Help: "About designing a query When you open a query in Design view, or open a form, report, or datasheet and show the Advanced Filter/Sort window (Advanced...
2
by: Tim Marshall | last post by:
The following is happening in two instances in A2003. The one I s\describe is the easiest one. Theme controls and autocorrupt have been turned off long ago. An unbound main form with a list...
4
by: ninrulz | last post by:
I have been working on a database to perform some of the tasks that I have been doing manually in Excel. One of those tasks is to sort and exclude duplicate data. The fields are as follows ...
2
by: franc sutherland | last post by:
Hello, I am using Access 2003. I have a query which shows a list of club meetings sorted by date. This query is displayed in continuous forms, in a subform. I would like to select a month on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.