Jump to content

Searcing a database (I'm new to PHP)


Tom Read

Recommended Posts

Hi all, currently being taught PHP in Computing at school and been set a task to do.

 

I've grasped it all pretty quickly, but now I'm stuck!

 

I have a database full of people's names and addresses etc. and need to create a drop down menu of their names, hit a search button, and for all their details to come up. I have all the names in the drop down menu and then I've managed to split that back into Forename and Surname using so I am able to do... WHERE Forename = $find_forename AND Surname = $find_surname (as putting them together into a drop down menu merges them together so it no longer knows that it's 2 different parts).

 

I'm not sure how to pull out the data of that one person however, as I already have accessed the database in order to display their names, if that makes sense. So I need to hit the search button, then have my code pull out that one person's data and display that, with the drop down menu still showing.

 

If someone could explain where I'm going wrong or what needs to be done, would be much appreciated!

 

I don't know if that makes sense or not, probably not!

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/207536-searcing-a-database-im-new-to-php/
Share on other sites

This can be done in straight PHP as well.

 

Since you've managed to split the forename and surname back up out of the drop down menu this is really simple.

 

After you split the names you basically re-query the database like:

 

$sql = "SELECT * FROM table WHERE Forename = '".$forename."' AND Surname = '".$surname."'";

$data = mysql_query($sql);

$data = mysql_fetch_array($data);

 

and from there you can echo it out like:

 

echo $data['Forename'];

echo $data['Surname'];

etc...  and of course you can throw it into tables if you want too.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.