开发者

PHP click text in a list, go to page with just clicked text

I have a table in a database that i'm showing all tweets in a page开发者_C百科, so how would i go about clicking a single tweet on the page and going to a new page that just shows that one tweet.

Some sort of GET through the href?

This is my PHP code:

while ($row = mysql_fetch_array($result)){
    echo "<p>" . $row['tweet'] . "</p><br />";
}


Make each tweet a link pointing to some page and pass the id of that tweet to the page:

while ($row = mysql_fetch_array($result)){
    echo "<p><a href='singlepage.php?id=" . $row['tweet_id']. "'>" . $row['tweet'] . "</a></p><br />";
}

Then on singlepage.php, you'd basically have the same code as the page listing all the tweets, except that it would include the sql "where tweed_id = " . $_GET['id'], so you'd only get that one result.

Be sure to validate your input so that if someone tweaks the URL and changes the ID, then they can't insert malicious sql commands.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜