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:
if (($action == "view")|($action == "delete")|($action == "deleteyes")|($action == "deletefile")|($action == "deletefileyes")) {
if ($action == "view") {
$clientid = $_GET;
$query = "SELECT * FROM insurance WHERE clientid='$clientid'";
$result = mysql_query($query) or die (mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows == "") {
echo "Could Not Select CLIENTID";
return 0;
}
while($rows = mysql_fetch_assoc('$result')) {
$name = $rows["name"];
$policyno = $rows["policyno"];
$type = $rows["type"];
$clientid = $rows["clientid"];
echo "<br>";
echo "<dd><dd><dd><dd><dd><dd>NAME: $name<br>";
echo "<dd><dd><dd><dd><dd><dd>POLICY NUMBER: $policyno<br>";
echo "<dd><dd><dd><dd><dd><dd>POLICY TYPE: $type<br>";
echo "<dd><dd><dd><dd><dd><dd>CLIENT ID: $clientid<br>";
}
echo "<center><br>";
// open this directory
$blank = "";
$dir = "$clients".$clientid."".$blank;
$myDirectory = opendir($dir);
// get each entry
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}
// close directory
closedir($myDirectory);
//count elements in array
$indexCount = count($dirArray);
// sort 'em
sort($dirArray);
// print 'em
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks width=60%>\n");
print("<TR><TH align=left>Filename</TH><TH>Action</th></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
print("<TR><TD width=80%><a href=\"Z:/Clients/$clientid/$dirArray[$index]\">$dirArray[$index]</a></td>");
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>");
print("</TR>\n");
}
}
print("</TABLE>\n");
echo "<br><center>[scan] [attach]<br><a href='insurance.php?'>[home]</a></center>";
}
This is snippet 2:
if (($value1 == "name")|($value1 == "policyno")|($value1 == "type")) {
# do some sense checking...
if ($value2 == "") {
$substring1 = "";
} else {
$substring1 = "AND $value2 = '$field2'";
}
if ($value3 == "") {
$substring2 = "";
} else {
$substring2 = "AND $value3 = '$field3'";
}
if ($value4 == "") {
$substring3 = "";
} else {
$substring3 = "AND $value4 = '$field4'";
}
# replace all spaces with MySQL wildcards...
$field1 = str_replace(" ","%",$field1);
$field2 = str_replace(" ","%",$field2);
$field3 = str_replace(" ","%",$field3);
# set the query string...
$query = "SELECT * FROM insurance WHERE $value1 LIKE ('%$field1%') $substring1 $substring2 $substring3";
# execute the query...
$result = mysql_query($query);
# split the results and set further variables...
$num_rows = mysql_num_rows($result);
$num_fields = mysql_num_fields($result);
if ($num_rows == 0) {
echo "No Results<br>";
return 0;
}
echo "<center>";
echo "<table border=1 width=65%>";
echo " <tr>";
echo " <th>NAME</th>";
echo " <th>CLIENT ID</th>";
echo " </tr>";
while($row = mysql_fetch_row($result)) {
for ($i=0;$i<=$num_rows;$i++) {
$id = "$row[$i]";
$query = "SELECT * FROM insurance WHERE id=$id";
$results = mysql_query($query);
while($rows = mysql_fetch_assoc($result)) {
$name = $rows["name"];
$policyno = $rows["policyno"];
$type = $rows["type"];
$clientid = $rows["clientid"];
echo " <tr>";
echo " <td width=44%>";
echo " <a href='insurance.php?action=view&clientid=$clientid'>$name</a>";
echo " </td>";
echo " <td width=44%>";
echo " <a href='insurance.php?action=view&clientid=$clientid'>$clientid</a>";
echo " </td>";
echo " <td width=6%>";
echo " <a href='insurance.php?action=view&clientid=$clientid'>[view]</a>";
echo " </td>";
echo " <td width=6%>";
echo " <a href='insurance.php?action=delete&clientid=$clientid'>[remove]</a>";
echo " </td>";
echo " </tr>";
}
}
}