Database row & Linking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
groovster
Forum Newbie
Posts: 10
Joined: Sun Nov 21, 2004 1:56 pm
Location: Uppsala, Sweden

Database row & Linking

Post 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
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post 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;
groovster
Forum Newbie
Posts: 10
Joined: Sun Nov 21, 2004 1:56 pm
Location: Uppsala, Sweden

THX

Post by groovster »

THX for writing so fast! :D

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

and

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]
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post 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
// ...
?>
groovster
Forum Newbie
Posts: 10
Joined: Sun Nov 21, 2004 1:56 pm
Location: Uppsala, Sweden

THX

Post by groovster »

Thanks buddy!
fl0w
Forum Newbie
Posts: 8
Joined: Tue Nov 23, 2004 2:19 pm
Location: Stockholm Sweden

Post 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.
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
Post Reply