Page 1 of 1
Database row & Linking
Posted: Tue Nov 23, 2004 12:51 pm
by groovster
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
Posted: Tue Nov 23, 2004 12:58 pm
by MarK (CZ)
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
Posted: Tue Nov 23, 2004 1:15 pm
by groovster
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:
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>
Weirdan | Help us, help you. Please use Code: 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]
Posted: Tue Nov 23, 2004 2:07 pm
by MarK (CZ)
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
// ...
?>
THX
Posted: Tue Nov 23, 2004 2:31 pm
by groovster
Thanks buddy!
Posted: Tue Nov 23, 2004 3:29 pm
by fl0w
MarK (CZ) wrote:Code: Select all
SELECT * FROM `friends` WHERE `id` = 'here_goes_the_id' LIMIT 1;
Don't use ` in a PHP script. No need for it.
Posted: Tue Nov 23, 2004 3:42 pm
by MarK (CZ)
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.
Posted: Tue Nov 23, 2004 5:53 pm
by John Cartwright
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.
I was just about to say, there are reserved words that you cannot use unless backticks, therefor, they are not useless.
Im sure there are other valid reasons for using them