-
Linking System
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:
PHP Code:
$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
-
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:
PHP Code:
$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.
-
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:)
-
By the way, does the header() function work in all browsers?
Thanks,
Mike:)
-
-
-
Just to let everyone know, I got it sorted through chromate's code...
Thanks chromate:)
-