User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,790 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,409 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 698 | Replies: 1
Reply
Join Date: Jan 2007
Posts: 2
Reputation: dbol is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dbol dbol is offline Offline
Newbie Poster

Searches only returning results for certain strings

  #1  
Jan 17th, 2007
Me and a buddy wrote some php code, and it searches the db for the string, returning results... The problem is, it only returns results for certain strings I search, for example, if I search a last name "Rodriguez", it works... if I search "Ro", it works. But if I search "Roq", nothing comes back... and I indeed have entries in the DB that would match that... When I search "Ro", they all appear, but if I try to specify further in the search, no results. This happens for most cases infact, with "Rodriguez" being one of the few cases the search is successful. I have no clue why this is happening.

This is snippet 1:

  1. if (($action == "view")|($action == "delete")|($action == "deleteyes")|($action == "deletefile")|($action == "deletefileyes")) {
  2. if ($action == "view") {
  3. $clientid = $_GET['clientid'];
  4. $query = "SELECT * FROM insurance WHERE clientid='$clientid'";
  5. $result = mysql_query($query) or die (mysql_error());
  6. $num_rows = mysql_num_rows($result);
  7. if ($num_rows == "") {
  8. echo "Could Not Select CLIENTID";
  9. return 0;
  10. }
  11. while($rows = mysql_fetch_assoc('$result')) {
  12. $name = $rows["name"];
  13. $policyno = $rows["policyno"];
  14. $type = $rows["type"];
  15. $clientid = $rows["clientid"];
  16. echo "<br>";
  17. echo "<dd><dd><dd><dd><dd><dd>NAME: $name<br>";
  18. echo "<dd><dd><dd><dd><dd><dd>POLICY NUMBER: $policyno<br>";
  19. echo "<dd><dd><dd><dd><dd><dd>POLICY TYPE: $type<br>";
  20. echo "<dd><dd><dd><dd><dd><dd>CLIENT ID: $clientid<br>";
  21. }
  22. echo "<center><br>";
  23. // open this directory
  24. $blank = "";
  25. $dir = "$clients".$clientid."".$blank;
  26. $myDirectory = opendir($dir);
  27. // get each entry
  28. while($entryName = readdir($myDirectory)) {
  29. $dirArray[] = $entryName;
  30. }
  31.  
  32. // close directory
  33. closedir($myDirectory);
  34.  
  35. //count elements in array
  36. $indexCount = count($dirArray);
  37. // sort 'em
  38. sort($dirArray);
  39. // print 'em
  40. print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks width=60%>\n");
  41. print("<TR><TH align=left>Filename</TH><TH>Action</th></TR>\n");
  42. // loop through the array of files and print them all
  43. for($index=0; $index < $indexCount; $index++) {
  44. if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
  45. print("<TR><TD width=80%><a href=\"Z:/Clients/$clientid/$dirArray[$index]\">$dirArray[$index]</a></td>");
  46. print("<td width=16%><a href='Z:/Clients/$clientid/$dirArray[$index]'>[view]</a> <a href='insurance.php?action=deletefile&clientid=$clientid&file=$dirArray[$index]'>[remove]</a></td>");
  47. print("</TR>\n");
  48. }
  49. }
  50. print("</TABLE>\n");
  51. echo "<br><center>[scan] [attach]<br><a href='insurance.php?'>[home]</a></center>";
  52. }

This is snippet 2:

  1. if (($value1 == "name")|($value1 == "policyno")|($value1 == "type")) {
  2. # do some sense checking...
  3. if ($value2 == "") {
  4. $substring1 = "";
  5. } else {
  6. $substring1 = "AND $value2 = '$field2'";
  7. }
  8. if ($value3 == "") {
  9. $substring2 = "";
  10. } else {
  11. $substring2 = "AND $value3 = '$field3'";
  12. }
  13. if ($value4 == "") {
  14. $substring3 = "";
  15. } else {
  16. $substring3 = "AND $value4 = '$field4'";
  17. }
  18. # replace all spaces with MySQL wildcards...
  19. $field1 = str_replace(" ","%",$field1);
  20. $field2 = str_replace(" ","%",$field2);
  21. $field3 = str_replace(" ","%",$field3);
  22.  
  23. # set the query string...
  24. $query = "SELECT * FROM insurance WHERE $value1 LIKE ('%$field1%') $substring1 $substring2 $substring3";
  25.  
  26. # execute the query...
  27. $result = mysql_query($query);
  28.  
  29. # split the results and set further variables...
  30. $num_rows = mysql_num_rows($result);
  31. $num_fields = mysql_num_fields($result);
  32. if ($num_rows == 0) {
  33. echo "No Results<br>";
  34. return 0;
  35. }
  36. echo "<center>";
  37. echo "<table border=1 width=65%>";
  38. echo " <tr>";
  39. echo " <th>NAME</th>";
  40. echo " <th>CLIENT ID</th>";
  41. echo " </tr>";
  42. while($row = mysql_fetch_row($result)) {
  43. for ($i=0;$i<=$num_rows;$i++) {
  44. $id = "$row[$i]";
  45. $query = "SELECT * FROM insurance WHERE id=$id";
  46. $results = mysql_query($query);
  47. while($rows = mysql_fetch_assoc($result)) {
  48. $name = $rows["name"];
  49. $policyno = $rows["policyno"];
  50. $type = $rows["type"];
  51. $clientid = $rows["clientid"];
  52. echo " <tr>";
  53. echo " <td width=44%>";
  54. echo " <a href='insurance.php?action=view&clientid=$clientid'>$name</a>";
  55. echo " </td>";
  56. echo " <td width=44%>";
  57. echo " <a href='insurance.php?action=view&clientid=$clientid'>$clientid</a>";
  58. echo " </td>";
  59. echo " <td width=6%>";
  60. echo " <a href='insurance.php?action=view&clientid=$clientid'>[view]</a>";
  61. echo " </td>";
  62. echo " <td width=6%>";
  63. echo " <a href='insurance.php?action=delete&clientid=$clientid'>[remove]</a>";
  64. echo " </td>";
  65. echo " </tr>";
  66. }
  67. }
  68. }
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2
Reputation: dbol is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dbol dbol is offline Offline
Newbie Poster

Re: Searches only returning results for certain strings

  #2  
Jan 17th, 2007
btw... Let me mention that, all searches are successful with 2 digits: i.e. "Ro", or "Ma" returns all results that at least match those strings.

But if I got beyond 2 digits, then the searches fail.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC