Jump to content

Why are results not returning?


CountryGirl

Recommended Posts

In one of my searches, some of the searched queries aren't returning, even though I know the data is in the database. I've run searches in my PHPMyAdmin to make sure the account number I'm searching with is in the DB and it is. But, when I run the search with the account number, nothing pulls up. Just an empty result.

 

My search coding is below. My coding is working totally fine with my other searches, it just won't pull up every record searched with this search, even though it is in the DB.

 

Exact search query:

 

 $query = "SELECT Appr_Value.ApprID as id, Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs
           FROM Appr_Value
           INNER JOIN Asmnt_Parcel
           ON Appr_Value.Account=Asmnt_Parcel.Account
           INNER JOIN Asmnt_Situs
           ON Appr_Value.Account=Asmnt_Situs.Account
           WHERE Appr_Value.Account LIKE '{$search}'
             ORDER BY Appr_Value.Account ASC";
   $result = mysql_query($query, $con) or die(mysql_error().": $query");

 

My whole coding:

 

$search = $_POST['search'];

if ($search) // perform search only if a string was entered.
{
   $con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error());
   mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());
   
   
   $query = "SELECT Appr_Value.ApprID as id, Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs
           FROM Appr_Value
           INNER JOIN Asmnt_Parcel
           ON Appr_Value.Account=Asmnt_Parcel.Account
           INNER JOIN Asmnt_Situs
           ON Appr_Value.Account=Asmnt_Situs.Account
           WHERE Appr_Value.Account LIKE '{$search}'
             ORDER BY Appr_Value.Account ASC";
   $result = mysql_query($query, $con) or die(mysql_error().": $query");

   if ($result)
   {
      echo "Results:<br><br>";
      echo "<table width=90% align=center border=1><tr>
      <td align=center bgcolor=#4A6B3F>Account</td>
      <td align=center bgcolor=#4A6B3F>Owners Name</td>
      <td align=center bgcolor=#4A6B3F>Situs</td>
      </tr>";
   
      while ($r = mysql_fetch_array($result))
      { // Begin while
         $act = $r["Account"]; 
         $name = $r["OwnersName"];
         $situs = $r["Situs"];
         echo "<tr>
            <td><a href='formresults.php?id=".$r['id']."'>$act</td>
            <td>$name</td>
            <td>$situs</td>
            </tr>";
      } // end while
      
      echo "</table>";
   }
   else
   {
      echo "Sorry, please try your search again.";
   }
}
else
{
   echo "";
}
?>

 

Thanks!

 

Link to comment
Share on other sites

If $search contains some non-printing characters (\r, \n, or \0) a query executed through php won't match anything in your database but if you copy/paste the resulting echo of $query, it could match values in your database.

 

Where is $_POST['search'] coming from and what do you get from the following -

 

var_dump($_POST['search']);

Link to comment
Share on other sites

If $search contains some non-printing characters (\r, \n, or \0) a query executed through php won't match anything in your database but if you copy/paste the resulting echo of $query, it could match values in your database.

 

Where is $_POST['search'] coming from and what do you get from the following -

 

var_dump($_POST['search']);

 

When I put the code example you gave and I searched an account number, this is what I get:

 

string(9) "730000031"

 

No results show up at all though. I'm not sure what you mean by "where is ' $_POST['search']' coming from?"  . . .

 

Is that where my problem is? Should I have something else there?

 

Thanks!

 

Link to comment
Share on other sites

The value in $search has a length that matches the visible characters.

 

Are you sure you have data that matches that value and are you executing that exact same query directly against your database when it does return results?

 

Using LIKE 'xxxxx' for an exact match is unusual (there are minor differences between a LIKE and an = comparison.) Have you tried an = comparison -

 

WHERE Appr_Value.Account = {$search} (try both without and with single-quotes around the value)

 

What is the definition of that column in your database table?

Link to comment
Share on other sites

The value in $search has a length that matches the visible characters.

 

Are you sure you have data that matches that value and are you executing that exact same query directly against your database when it does return results?

 

Using LIKE 'xxxxx' for an exact match is unusual (there are minor differences between a LIKE and an = comparison.) Have you tried an = comparison -

 

WHERE Appr_Value.Account = {$search} (try both without and with single-quotes around the value)

 

What is the definition of that column in your database table?

 

What value are you talking about when it comes to the $search? Maybe that's where I'm confused. I haven't specified any value to it or length of anything. Maybe you could explain a little?

 

Yes, I just tried the "=" several times and with several different combinations. And nothing works. It still is only returning some and not returning others, that I know are in the database. The definition of that column I'm trying to search from are account numbers. They are all the same length and are 9 numbers long.

 

If you have suggestions on a better way to do something, that'd be great! I am really lost in how to fix this problem.

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.