bachx Posted February 1, 2007 Share Posted February 1, 2007 Hello all, I'm wondering how can I create auto generated dynamic links where those links can interact directly with the DB, call a function, go to another page, etc. For example, I have created a simple forum. I want next to each topic a "Delete" link where I can delete this topic simply by clicking it. It should look something like this: (.../mysite/index.php?delete=2411). I hope I made myself clear. Any help is really appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/36610-solved-creating-a-dynamic-link/ Share on other sites More sharing options...
trq Posted February 1, 2007 Share Posted February 1, 2007 Its probably going to be easier to give you an example if you post the code that displays your topics. Quote Link to comment https://forums.phpfreaks.com/topic/36610-solved-creating-a-dynamic-link/#findComment-174429 Share on other sites More sharing options...
bachx Posted February 1, 2007 Author Share Posted February 1, 2007 Alright, here is my simplified code. I'm still a beginner in PHP, everything was going smooth until this point. So any help is really appreciated. $show_topics = mysql_query("SELECT * from topics"); print "<table border=\"1\" width=\"100%\">\n"; while ( $row = mysql_fetch_array( $show_topics) ) { print "<tr><td align=\"left\">".stripslashes($row['username'])."</td></tr>"; print "<tr><td align=\"left\">".stripslashes($row['reply'])."</td></tr>"; } print "</table>\n"; So basically I want to add another print line in this table, which should be something like: print "<td align=\"left\"><a href=\"forums.php?id=". $row['id'] ."\">Delete reply</a></td>"; But apparently, clicking this link won't do anything. I want it to delete the reply which has an id of "$row['id']" whenever I click the "Delete reply" link, maybe call a reply_delete($row['id']) function. So I'm wondering how is this done. Quote Link to comment https://forums.phpfreaks.com/topic/36610-solved-creating-a-dynamic-link/#findComment-174441 Share on other sites More sharing options...
redarrow Posted February 1, 2007 Share Posted February 1, 2007 only an example ok but your get the dreft. page_one.php <?php // database connection $query="select * from what_ever where topic_id='$topic_id' "; $result=mysql_query($query)or die("problams with query"); while($record=mysql_fetch_assoc($result)){ $topic_id=$record['topic_id']; echo"<a href='page_two.php?$topic_id=$topic_id&cmd=delete'>delete topic</a>"; } ?> page_two.php <?php // database connection. if($_GET['cmd']=="delete"){ $query="delete from what_ever where topic_id='$topic_id'"; $result=mysql_query(query); echo"file deleted"; }else{ echo"sorry server problams"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/36610-solved-creating-a-dynamic-link/#findComment-174444 Share on other sites More sharing options...
bachx Posted February 1, 2007 Author Share Posted February 1, 2007 Worked like charm. Big thanks! Quote Link to comment https://forums.phpfreaks.com/topic/36610-solved-creating-a-dynamic-link/#findComment-174455 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.