2013-12-13 51 views
-1

我有一個簡單的博客應用程序,我將PHP和MySQL放在一起(條目位於那裏)。我有一個博客位於一些網址www.url.com/blog.php,但顯示「所有」博客條目,但每個人必須有它自己的網址,當你點擊它,導致www.url.com/blog.php?postID=1,www.url.com/blog.php?postID=2,www.url.com/blog.php?postID=3,www.url.com/blog.php?postID=so on如何在URL上附加這些postID?如何在問號'?'後創建這些網址追加URL創建個人博客條目頁面

所以我的博客看起來像......

#FORM shown like, a PHP script insert the entry into MySQL database 
name: ___________ 
Date: ___________ 
Blog entry:______ 
_________________ SUBMIT 

# All blog entries are shown here where PHP script select * from blog_table 

BlogID Author Date Entry 
1  john 1-1-1 Something 
2  dave 1-2-1 Something else 
. 
. 
. 

但這些blogID必須有附加的URL,這樣,這樣當你點擊1應該有它自己的鏈接

BlogID 1 = www.url.com/blog.php?postID=1 
BlogID 2 = www.url.com/blog.php?postID=2 
BlogID 3 = www.url.com/blog.php?postID=3 

你們會如何做到這一點?建議。謝謝。

+0

您創建的任何其他鏈接的方式相同。 '?'後面的東西只是一個傳遞給你的PHP腳本的變量。在您的PHP腳本中,您將可以訪問'$ _GET ['postID']'變量,這將是字符串末尾的數字。使用它從數據庫中獲取正確的條目。 –

+0

@JustinWood hmm – mythoslife

+0

@JustinWood我在我的博客入口頁面上使用$ _POST。我是否必須將其更改爲$ _GET才能訪問變量? – mythoslife

回答

0

在你blog.php的文件,把這個代碼:

<a href="http://www.url.com/blog.php?id=1">Blog 1</a><br/> 
<a href="http://www.url.com/blog.php?id=2">Blog 2</a><br/> 
<a href="http://www.url.com/blog.php?id=3">Blog 3</a><br/> 

<?php 

$blogid = $_GET['id']; 

//Pull the blog from the database 
$query = "SELECT Entry FROM blog_table WHERE BlogID='$blogid'"; 
// Perform the query . . . 


echo "Here is the blog entry for blog $blogid"; 
// Display the results of the query . . . 
?> 
+0

謝謝我會盡力的! – mythoslife

0

如果您有存儲爲一個變量的博客ID只是呼應入網址

$ blogId = my_function_to_get_blogid();

echo'www.url.com/blog.php?postID='。 $ blogId;

相關問題