Originally posted by salsa_dancer
OK I have managed to get a search form going - have connected to the database.. When I do the search it returns 0 results when I know that they are there... what is wrong here?
How do you know there are no results? You never actually read the results in your code.
what is $query doing? It doesn't get used anywhere!
<td width="70%" bgcolor="#3e73d3"><font face="Tahoma" size="1" color="#FFFFFF">Search
database for:</font><font face="Tahoma" size="2" color="#FFFFFF">
' <b>
<?=$city?>
</b> '</font></td>
<?php
if (isset($mode) && ($mode = "full")){
$limiter = 9999;
} else {
$limiter = 10;
}
{
$query = "SELECT * FROM Addresses WHERE $city LIKE '%$city%' ORDER BY Rank ASC LIMIT 0,$limiter";
$numero = mysql_query("SELECT * FROM Addresses WHERE $city LIKE '%$city%' ORDER BY Rank, $by DESC");
?>
That part is ok, but weird. The mysql_query statement should work. but $query does nothing but assign a string to a var named query.
And that limiter, are you seriously going to allow someone to query for 9999 records? that will kill your site when too many people are trying to do the full query at once.
As for the code below, what is $data? you never assigned anything to it.
If you want to create an object called data that contains your database query results, you need to put it in a loop and re-create the object in each iteration.
before the code below, do this:
while($data = mysql_fetch_assoc($numero)){
$numero is the resource link identifier that points to the query results in mysql. You need to reference it by calling mysql_fetch_row, mysql_fetch_array, or mysql_fetch_assoc.
Read the mysql functions part of the php manual here:
http://www.php.net/manual/en/function.mysql-query.php
http://www.php.net/manual/en/function.mysql-fetch-assoc.php
now, at the end of this block of code, close the while loop.
<font face="Arial, Helvetica, sans-serif" size="3" color="#0000CC">
<?php
echo "$data->Name";
?>
<br>
</font><font face="Arial, Helvetica, sans-serif" size="-1" color="#000000">
<?php
echo "<font color=\"008000\">$data->Name</font><br>\n";
if ( $data->Address <> ''){
echo $data->Address;
}
//CODE SNIPPED FOR READABILITY
}//end while loop