0 Replies - 785 Views - Last Post: 10 August 2010 - 03:58 PM Rate Topic: -----

#1 Guest_Pedro Cassian*


Reputation:

Help needed making a facebook like autosuggest that detects keyboard n

Posted 10 August 2010 - 03:58 PM

Hi, So im basically trying to make a simple search engine site that can search nearby restaurants using an easy to use facebooklike autosuggestion search, i basically used this tutorial to make the facebook like autosuggestion

http://www.9lessons....ax-and-php.html

but It doesnt have an onclick event, or keyboard navigation, and thats pretty important for the site im making

heres the link for the site im constructing
http://www.thebaroom.com/hambre2/

it looks nice but it needs a lot of work to function properly, I would like to have an onclick event on the titles of the restaurants, on the types of places, and on the zones they are in, so they would query them in mysql and display the results in a box with more info

I also have a critical flaw in the search, that it doesnt seperate keywords with a space, therefore if i type "bretta pizza" nothing will show up, because bretta is the name of the place, and pizza is the type, I think using a full text search could solve that issue, but i have no idea how to accomplish it, Ive tried a couple of things but I havent had any luck, heres a tutorial that explains it, but I didnt get it, I also thought exploding the text would work, but I couldnt get it to work either

http://forum.codecal...-php-mysql.html

this is my search php, I think its the only code needed
<?php
include('config.php');
if($_POST)
{

$q=$_POST['searchword'];

$sql_res=mysql_query("SELECT * FROM test_user_data WHERE ( fname like '%$q%'  or lname like '%$q%' or type like '%$q%' ) order by fname ASC LIMIT 4");
while($row=mysql_fetch_array($sql_res))
{
$fname=$row['fname'];
$lname=$row['lname'];
$type=$row['type'];
$img=$row['img'];
$country=$row['country'];
$address=$row['address'];

// this is meant to get the # of rows found for the query, however it does not
$num_rows = mysql_numrows($sql_res);


// maybe i can use explode to split the lines and create several querys, but how?
$q2=explode(" ", $q);


$re_fname='<b>'.$q.'</b>';
$re_lname='<b>'.$q.'</b>';
$re_type='<b>'.$q.'</b>';

$final_fname = str_ireplace($q, $re_fname, $fname);

$final_lname = str_ireplace($q, $re_lname, $lname);

$final_type = str_ireplace($q, $re_type, $type);


// how can I make the output capitalize every first letter of the word? using ucfirst or ucwords, but how?
$name = ucfirst($final_fname);

?>

<div class="display_box">
  <table width="400" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="100"><img src="user_img/<?php echo $img; ?>" style="width:100px; height:43px; float:left; margin-right:6px" /></td>
      <td width="150"><?php echo $name; ?> <?php echo "|&nbsp;&nbsp;" . $final_type; ?> <?php echo "<br>" . $final_lname; ?> </td>
      <td width="150"><?php echo $country; ?> <?php echo "<br>" . $address; ?></td>
    </tr>
  </table>
  </div>

<?php
}

}
else
{


}


?>

<div class="display_box3" align="center">

<?php echo "<b> Ver mas resultados de $fname </b> <br>
Mostrando los primeros $result resultados";?>
</div>




im trying for the results box kinda end up looking like this
Posted Image

I hope anyone can help, my php savvy classmates arent lending a hand or dont know either, i dunno

Is This A Good Question/Topic? 0

Page 1 of 1