Jump to content

[SOLVED] Creating a dynamic link?


bachx

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

?>

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.