mitman Posted July 9, 2009 Share Posted July 9, 2009 I've looked around for something similar to this, but I couldn’t find anything. I have a script that allows users to post various information (comments, name etc.) to a MYSQL database. Each post is assigned a unique id when it is entered into the database. What I am trying to do now is retrieve that data and give each post its own unique url (For example, one post could have the url http://www.example.com/showresults.php?id=3943). If one was to go to that link, they would see a specific post and that url would be unique to that post. I understand that you have to use variables but I don’t quite get how I would go about doing this. Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/165384-unique-urls-for-individual-posts-in-mysql-database/ Share on other sites More sharing options...
ignace Posted July 9, 2009 Share Posted July 9, 2009 INSERT INTO content VALUES (1, 'http://localhost/index.php?p=ABOUTS'); INSERT INTO content VALUES (2, 'http://localhost/index.php?p=CONTACTS'); SELECT * FROM content WHERE href = 'http://localhost/index.php?p=ABOUTS' You are probably trying to create a content management system where you work with 'pages', right? Quote Link to comment https://forums.phpfreaks.com/topic/165384-unique-urls-for-individual-posts-in-mysql-database/#findComment-872220 Share on other sites More sharing options...
mitman Posted July 9, 2009 Author Share Posted July 9, 2009 Kind of, except I'm trying to make one page display an entry from a mysql database. This page thats displaying the entry has a unique url with an "?id=" Quote Link to comment https://forums.phpfreaks.com/topic/165384-unique-urls-for-individual-posts-in-mysql-database/#findComment-872324 Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 <?php if (empty($_GET['id'])) { //?id= does not exist, what to do? } $id = (int) $_GET['id']; $query = 'SELECT * FROM contents WHERE id = %u'; $fquery = sprintf($query, $id); $result = mysql_query($fquery, $db); $row = mysql_fetch_assoc($result); //work with $row print $row['title']; print $row['excerpt']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/165384-unique-urls-for-individual-posts-in-mysql-database/#findComment-872767 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.