PDA

View Full Version : Linking System



Mike
10-15-2003, 09:50 AM
Hi all,

Using PHP, I would like to create a similar linking system to the one used on this site. So each link is entered into a database, given an id, and linked to like "out.php?id=4" or something.

I haven't used MySQL for ages, so I'm not completely sure how to do it. I think it would involve a for statement with mysql_num_rows, something like:



$result = mysql_query("SELECT * FROM table", $dbcnx) ;

for ($x= 0; $x < mysql_num_rows($result); $x++)
{
$row = mysql_fetch_assoc($result) ;

echo ("<a href=\"out.php?id=") ;
echo ($row['ID']) ;
echo ("\">") ;

As I said, it's a long time since I last used MySQL and PHP together, so chances are that's probably wrong.

Please could anyone give me any advice on an easier way or anything?

Thanks a lot,
Mike

chromate
10-15-2003, 02:52 PM
I'm not sure exactly what you're trying to do. Your code will produce a list of href tags. 1 for each table row.

If you're after the code for the "out.php" script, it would be something like:




$sql = "SELECT url FROM links_table WHERE id = '$id'";
$result = mysql_query($sql, $db);

if($result) {
$url = mysql_result($result, 0);
header("location: $url");
} else {
echo "ID not found";
}



Or something like that anyway.

Mike
10-16-2003, 08:02 AM
Yeh, I see what you mean. I got it from another script I did sometime last year.

Anyway, I will have another bash with your idea...

Thanks a lot,
Mike:)

Mike
10-26-2003, 02:45 PM
By the way, does the header() function work in all browsers?

Thanks,
Mike:)

Chris
10-26-2003, 07:46 PM
yes

Mike
10-27-2003, 09:01 AM
Thanks:)

Mike
11-02-2003, 02:55 AM
Just to let everyone know, I got it sorted through chromate's code...

Thanks chromate:)

chromate
11-02-2003, 03:55 AM
no probs