I have posted this script previously, asking why the following code does not produce the correct output.
WHAT SHOULD HAPPEN:
the script should return all the listings in the database which match the search value.
WHAT ACTUALLY HAPPENS:
no mater the '$searchValue' as long as there is only one item in the database it displays that single result, no matter if it matched the search value or not.
If there is more than one lising in the database, no matter the content, it displays this error message:
Query SELECT * FROM listings WHERE MATCH trading AGAINST ('') returned no results.
THE CODE
<?php
// singleSearch.php
include 'error.inc';
include 'db.inc';
//----------------------------------------------------------------------------------------
//connect to the database
if(!($connection = @ mysql_pconnect($hostname, $username, $password)))
die("Could Not Connect to database");
if (!mysql_select_db($databaseName, $connection))
showerror();
//-----------------------------------------------------------------------------------------
// get user search input
$searchValue = $HTTP_POST_VARS["searchValue"];
$searchValue = trim($searchValue);
print $HTTP_POST_VARS['searchValue'].'<br>';
print $searchValue.'<br>';
print_r($HTTP_POST_VARS);
// Build a query:
$query = "SELECT * FROM listings WHERE MATCH trading AGAINST ('$searchValue')";
// Run the query. If the query fails, it won't return a result set identifier:
$result = mysql_query($query);
if(!$result) {
echo "Query $query failed.";
// If the query failed, MySQL is usually friendly enough to offer a reason why:
echo mysql_error();
}
else {
// Just because a query executed succussfully doesn't necessarily mean there are rows in the result set.
// So test the number of rows in the result set:
if(!mysql_num_rows($result)) {
echo "Query $query returned no results.";
}
else {
while($data = mysql_fetch_array($result)) {
// process the data array for each row in the result set here...
// Get vars
$trading = $data["trading"];
$for_ = $data["for_"];
$wac_1 = $data["wac_1"];
$wac_2 = $data["wac_2"];
$enter_time = $data["enter_time"];
$overdue_time = $data["overdue_time"];
$user_id = $row["user_id"];
// find time left
// Get the number of seconds:
$seconds = $overdue_time - time();
// the number of whole days is the number of seconds / 86400:
$days = (int)($seconds / (60 * 60 * 24));
// get any remainder:
$r = (int)($seconds % (60 * 60 * 24));
if($r) {
// the number of hours is the remainder divided by 3600:
$hours = (int)($r / (60 * 60));
$r = (int)($r % (60 * 60));
if($r) {
$minutes = (int)($r / 60);
$secs = (int)($r % 60);
}
}
$time_left = date(d, $days) . " days " . date(h, $hours) . " hours " . date(i, $minutes) . " mins " . date(s, $secs) . " secs";
// make over_duetime a user format
// Line contents for each listing
$line1 = "<br><br>$user_id : Wants To Trade $trading For $for_<br>";
// if wac's have no value then display line
if (!(empty($wac_1)) && (!(empty($wac_2)))){
$line2 = "Will also Consider Trading for: $wac_1; $wac_2;<br>";
}
elseif (empty($wac_1) && empty($wac_2)){
$line2 = "$user_id, is not willing to trade for anything else";
}
$line3 = "<a href=\"listing.php\">View Complete Listing</a> Listing ends in $time_left on " . date('m/d/Y', $overdue_time);
// start a <table>, print one listing; Organize results to fit page & display results
echo $header;
echo $ads;
echo "\n<table>\n<tr>" . "\n<tr>" . "\n\t<td>" . $line1 . " </td>
\n<tr>" . "\n<tr>" . "\n\t<td>" . $line2 . " </td>
\n<tr>" . "\n<tr>" . "\n\t<td>" . $line3 . " </td>";
echo $footer;
} // end while
} // end else
} // end else
?>
Is there a 'better' way to code this?
What could be wrong?
How could i check my mysql configurations?