cleary1981 Posted July 24, 2008 Share Posted July 24, 2008 Hi I have the following code that displays the name and descriptions for each record in my table. The trouble is i want the name to be a clickable link. Can this be done? heres my code <?php if ($_COOKIE["cost"] == "1") { } else { //redirect back to login form if not authorised header ("Location: loginform.html"); exit; } require "config.php"; $sql="select module_name, mod_desc from module where confirmed=0"; $result = mysql_query($sql) or trigger_error(mysql_error()); ?> <table border="6" cellspacing="2" cellpadding="2"> <tr> <th>Name</th> <th>Description</th> </tr> <?php while($nt=mysql_fetch_array($result)){ echo "<tr><td>$nt[module_name]</td><td> $nt[mod_desc]</td></tr>"; // name class and mark will be printed with one line break at the end } ?> Quote Link to comment Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 <?php if ($_COOKIE["cost"] == "1") { } else { //redirect back to login form if not authorised header ("Location: loginform.html"); exit; } require "config.php"; $sql="select module_name, mod_desc from module where confirmed=0"; $result = mysql_query($sql) or trigger_error(mysql_error()); ?> <table border="6" cellspacing="2" cellpadding="2"> <tr> <th>Name</th> <th>Description</th> </tr> <?php while($nt=mysql_fetch_array($result)){ print "<tr><td><a href=\"mypagehere.php\">{$nt['module_name']}</a></td><td> $nt[mod_desc]</td></tr>"; // name class and mark will be printed with one line break at the end } ?> Quote Link to comment Share on other sites More sharing options...
cleary1981 Posted July 24, 2008 Author Share Posted July 24, 2008 what i want is for all the links to open the same page but be specific to that record. How would you go about that? Quote Link to comment Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 Well, you need to start by having a unique field in your DB table. Maybe an autoincrementing integer. Then, assuming you have that... you could use this.... <?php if ($_COOKIE["cost"] == "1") { } else { //redirect back to login form if not authorised header ("Location: loginform.html"); exit; } require "config.php"; $sql="select module_name, mod_desc from module where confirmed=0"; $result = mysql_query($sql) or trigger_error(mysql_error()); ?> <table border="6" cellspacing="2" cellpadding="2"> <tr> <th>Name</th> <th>Description</th> </tr> <?php while($nt=mysql_fetch_array($result)){ print "<tr><td><a href=\"" . $_SERVER['PHP_SELF'] . "?id={$nt['my_id_field']}\">{$nt['module_name']}</a></td><td> $nt[mod_desc]</td></tr>"; // name class and mark will be printed with one line break at the end } ?> Quote Link to comment Share on other sites More sharing options...
cleary1981 Posted July 24, 2008 Author Share Posted July 24, 2008 Sorry I meant to say the links all point to one page addComponents.php. Your code works great cheers but just one last question. In the new page how do i reference id? Quote Link to comment Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 You do this... $myID = (int) $_GET['id']; (if you're following on from the earlier example) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.