Hello Everyone,
I am a newbie and I did tried searching this topic for help before asking for help. Also forgive me if I am posting in the wrong forum.
Here is my problem:
I have a Mysql database with people's details, such as name,address,contacts, etc.
I would like to run through this table and display all the names in a vertical list. I have already done this.
Now from this list of names I would like viewers to click on the names which will bring up the entire profile(record) of this clicked name from the MySQL table. This I need advice on how to accomplish this.
eg.
John Doe
Tom Dick
Cindy Sue
I would like when you click on Tom Dick the records for Tom Dick in the database (address/contact/etc) to come up.
I'll appreciate all help.
Thanks
Dave
Links on MySQL output list
Moderator: General Moderators
Re: Links on MySQL output list
I will assume that your database table has a primary key field (an ID number, for example). That's absolutely essential because it's the only way to identify what record you want to display the details for. In the query that you use to get the names for your vertical list, you must select the names AND the key field, something like this: Then when you echo each line for your list, you format it either as an HTML hyperlink (anchor) or as an HTML span with an onClick property--in either case, calling another PHP script using the appropriate key field data as a URL parameter. That probably sounds complicated to you at this point, but it's really easier to do than to describe. You probably now have a loop that extracts rows from your query result set and prints them, right? This isn't much more complicated, except that you need the name AND the key field for each entry. It will look something like this, roughly: or the last line could be like:
Now you need to write details.php script, which will look for a GET parameter named 'key': and then it will generate a query to find the record identified with $key and format the display for the browser.
Notice that if you have a lot of names in the database, your first page with the vertical list is going to be really long. This is not normally done this way. Instead, it's usually desirable to ask the user to enter a name or part of a name and have the database search for matching records.
Code: Select all
$sql = "SELECT lastname, firstname, id FROM xxxxxx";Code: Select all
...
$sql = "SELECT lastname, firstname, id FROM xxxxxx";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result)) {
echo "<a href='details.php?key=".$row['id'].">".$row['firstname']." ".$row['lastname']."</a><br />";
}Code: Select all
echo "<span onClick='window.location=\"details.php?key=".$row['id'].";\">".$row['firstname']." ".$row['lastname']."</span><br />";Code: Select all
if(isset($_GET['key']) $key=$_GET['key'];Notice that if you have a lot of names in the database, your first page with the vertical list is going to be really long. This is not normally done this way. Instead, it's usually desirable to ask the user to enter a name or part of a name and have the database search for matching records.
Re: Links on MySQL output list
Thanks Willie Nelson,
I will try this out and post a feed back soon.
Your help is highly appreciated.
Thanks
Dave
I will try this out and post a feed back soon.
Your help is highly appreciated.
Thanks
Dave