Forum Moderators: coopster

Message Too Old, No Replies

PHP connect for Live Search

need help connecting to my db

         

urbanmac

5:29 pm on Nov 24, 2005 (gmt 0)

10+ Year Member




The live search on BitFlux is great, I'd like to add it to a site I'm working on.
Problem is in the wiki he really glances over the part where you use php to connect to your datbase.

Has anyone implement live search and if so couldl they post the php connect script removing their conenction details but add in stuff like 'DATABASEUSER' 'DATABASEPASSWORD' etc - a really dummies guide I know but I'm a dummy!

lobo235

6:46 pm on Nov 24, 2005 (gmt 0)

10+ Year Member



Check out the mysql_connect() [php.net] function. There should be some good information there to get you started.

urbanmac

7:41 pm on Nov 24, 2005 (gmt 0)

10+ Year Member



I gave that a go earlier, I can connect to my database fine but I'm not getting search results back, I'm stuck now.

urbanmac

8:09 pm on Nov 24, 2005 (gmt 0)

10+ Year Member



this is my connection script:

<?php

$dhost = 'localhost';
$duser = 'username';
$dpass = 'password';
$dname = 'databasename';

@mysql_connect($dhost, $duser, $dpass) or
die("mySQL service unavailable please try again later");

@mysql_select_db($dname) or
die("Database $dname unreachable, contact an administrator");

?>

Easy stuff,now how does the live search return results from certain fields in certain tables in my database?

lobo235

4:44 am on Nov 25, 2005 (gmt 0)

10+ Year Member



You need to use a SELECT query and use a WHERE clause to specify which rows you want to return. For example:

SELECT * FROM `articles` WHERE title LIKE '%blah%' OR author LIKE '%blah%'

You will just need to modify the above to work with your specific table/columns. Then use the mysql_query() function to perform the query and mysql_fetch_row() or mysql_fetch_assoc() to read each row and process it.