Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Attaching Variables to Links

Code Wizard, 12-30-2006

Lets say u are selecting all data from a database for a listing, then u want to have a link that goes to the details of the record. This is the code you "Could" use to do so.

####### List.php ######
<?

$link = mysql_connect("host","user","pass");

$db = mysql_select_db("database", $link);

//* Get all records
$sql = "SELECT * FROM table";

$sql_result = mysql_query($sql,$link);

while ($row = mysql_fetch_array($sql_result)) {
//* In place of $id u would put the name of the column that u want displayed, remember you can use multiple columns when creating these
$id = $row["id"];
//* echo the link to html
echo "<a href="detail.php?name=$name&id=$id">$id</a>";
};
mysql_free_result($sql_result);
mysql_close($link);
?>
############ Detail.php ############
<?
$link = mysql_connect("$host","$user","$pass");
$db = mysql_select_db("database", $link);
$sql = "SELECT * FROM table where id = '$id'";
$sql_result = mysql_query($sql,$link);
while ($row = mysql_fetch_array($sql_result)) {
$detail = $row["detail"];
$detail1 = $row["detail1"];
$detail2 = $row["detail2"];
echo "
Detail : $detail
Other Detail : $detail1
MORE Detail : $detail2
";
};
mysql_free_result($sql_result);
mysql_close($link);
?>
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions