Jump to content

Creating a link inside a loop using id


lebedev9114

Recommended Posts

Hey,

I am knew to php , any help would be appreciated. So in the database i want to create for example their is a name of a player Mark Macguire and I want to have another database field called  MORE INFO , for every single following  players name after Mark. the MORE INFO will direct a person to a new page . Here is what i got so far:

 

<th><a href="/getlink.php?id=<?php echo $row['id']; ?>">More Info</a></th>

 

I don't know however how to write the getlink.php which makes this code , work can anyone help out please!

Link to comment
https://forums.phpfreaks.com/topic/177074-creating-a-link-inside-a-loop-using-id/
Share on other sites

Hi lebedev9114,

 

A good start would be to use the $_GET function and use the variable retrieved to perform a query on your database.  For example:

 

<?php
//This function makes $_GET or $_POST data safe
function make_safe($unsafe)
{
require("your database connect script here.php");
$safe = mysql_real_escape_string(strip_tags(trim($unsafe)));
return $safe;
}

//Perform the MySQL Query on the database based on the id
$sql = mysql_query("SELECT * FROM database WHERE id = '".make_safe($_GET['id'])."' ORDER BY id");

 

I hope this helps.

Not sure if I understand, but I would change it from

 

<a href="/getlink.php?id=<?php echo $row['id']; ?>">More Info</a>

to

 

<a href="/getlink.php?id=$row['id']">More Info</a>

 

then the retrieving code

 

$name = $_GET[id];
echo" Name: $name";

etc.

 

If $name is going to be used in a database query then you need to make it safe.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.