Jump to content

Unique urls for individual posts in mysql database


mitman

Recommended Posts

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.

 

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?

<?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'];
?>

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.