Forum Moderators: coopster

Message Too Old, No Replies

How do you write a search query in PHP?

         

Latch

12:34 am on Jul 8, 2005 (gmt 0)

10+ Year Member



Hi guys, i originally put this message in the New to Web Development forum but I think it is better suited to here. Now to the problem, I have developed a database in Mysql, and I have populated it with my data, but now how do I query it (i.e. perform a two criteria search)? How do i link the database to the web page? How do I write the query and link the query to my web page? And how do I link the results to my web page?

The search I want to do will be on First Name and Surname. And the Database is called Work_Experience.

Thanks in advance

Latch

dreamcatcher

6:32 am on Jul 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Latch,

Check out this post, it may be of some help:

[webmasterworld.com...]

dc

kenchix1

6:35 am on Jul 8, 2005 (gmt 0)

10+ Year Member




but now how do I query it (i.e. perform a two criteria search)?

first you have to open your database first before you can query it.

---this will open your connection

$conn = mysql_connect($hostName, $dbUser, $dbUserPw) or die ('Error connecting to database');
mysql_select_db($dbName);


How do i link the database to the web page?

I don't quite understand your question but if you mean how will you display your data , you should fetch the query result first and put it on variables.


How do I write the query and link the query to my web page? And how do I link the results to my web page?

---this is your query
$query = "select surname, firstname from `work_experience`.mytable where surname='$surnamecriteria' and firstname='$firstnamecriteria'";

---this will query your table
$result = mysql_query($query);

---this will fetch your data and put it in variables
list($surname, $firstname)= mysql_fetch_row($result);

---this will display the variables
echo "Search match is $firstname and $surname";