Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/36610-solved-creating-a-dynamic-link/
Share on other sites

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.

 

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";
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.