Database row & Linking
Moderator: General Moderators
Database row & Linking
Hi all!
This should be simple but i just can't do it.
Ok here it goes:
I have a dabase with the name, phone, address etc of my friend. Ican display all the names with a script that i have. I would like to be able to click on any friends name and the code to display more information on my friend. How do i do this?
I'm using Mysql
Regards,
G-Man
This should be simple but i just can't do it.
Ok here it goes:
I have a dabase with the name, phone, address etc of my friend. Ican display all the names with a script that i have. I would like to be able to click on any friends name and the code to display more information on my friend. How do i do this?
I'm using Mysql
Regards,
G-Man
- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
You probably have some id assigned to each person. So simply place a link with id (e.g. /friend.php?id=4). In friend.php, you can easily use something like
Code: Select all
SELECT * FROM `friends` WHERE `id` = 'here_goes_the_id' LIMIT 1;THX
THX for writing so fast!
To make them clickable is not a problem. The problem is to create the code that will know what I clicked on and display that information.
With other words i dont have the code to get the rest.
Here is what i have to display and make it clickable:
Weirdan | Help us, help you. Please use
To make them clickable is not a problem. The problem is to create the code that will know what I clicked on and display that information.
With other words i dont have the code to get the rest.
Here is what i have to display and make it clickable:
Code: Select all
<?php
$result = mysql_query("select * from friends order by friendName asc");
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width="30%" height="25">
<font face="verdana" size="1" color="black">
<a href="est2.php?id=<?php echo $row["friendId"]; ?>
</font>
</td>Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
est2.php:
Code: Select all
<?php
$fID = mysql_real_escape_string($_GET["friendId"]);
$sqlQuery = "SELECT * FROM `friends` WHERE `friendId` = '$fID' LIMIT 1";
$result = mysql_query($sqlQuery);
// ...
// Do here whatever you want with the data about user
// ...
?>Don't use ` in a PHP script. No need for it.MarK (CZ) wrote:Code: Select all
SELECT * FROM `friends` WHERE `id` = 'here_goes_the_id' LIMIT 1;
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I was just about to say, there are reserved words that you cannot use unless backticks, therefor, they are not useless.MarK (CZ) wrote:There is. E.g. I've used `key` as a name of one column - it's a MySQL keyword so queries without ` doesn't work.
Im sure there are other valid reasons for using them