我开发自己的PHP Mysql站点。从嗅嗅网址获取文章从MySQL数据库
我使用的ID这样来获取数据:mysite.com/articles.php?id=12
现在我想用塞更改URL:
mysite.com/articles/google-search
或
mysite.com/articles.php?article=google-search
我不想使用ID和数字。
我的表:
+----+---------------+---------+------------------------------------+
| id | title | article | urlslug |
+----+---------------+---------+------------------------------------+
| 12 | google search | xxxxxxx | google-search |
| 13 | bing yahoo | xxxxxxx | bing-yahoo |
| 14 | friendly seo | xxxxxxx | friendly-seo |
+-------------------------------------------------------------------+
我用下面的代码通过ID来获得数据:
$id = $_GET['id'];
$id = mysqli_real_escape_string($conn,$id);
$query = "SELECT * FROM `table` WHERE `id`='" . $id . "'";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo ($row['title']);
echo ($row['article']); }
我想上面的代码通过替换urlslug它说:Invalid ID specified.
我一派,甚至搜查在堆栈问题我没有得到任何帮助。请帮助我。提前致谢。
你可以重复'回声$ _GET [ 'id'];' – uno