Jump to content

Help giving article its own url


FatDank

Recommended Posts

I need to have this so my article has its own url. So say i go to articles.php?article=23 it will display only the article with the id 23.

 

Here is what I have thats not working:

 

<?
$conn = mysql_connect('','','') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('',$conn) or trigger_error("SQL", E_USER_ERROR);


$sql = "SELECT id, post FROM articles";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);


switch ($_GET['article']) {

    case $list['id'];

	while ($list = mysql_fetch_assoc($result)) {
            echo $list['post'];
	}

        break;
}
?>

Link to comment
Share on other sites

I'm not really sure what you're trying to do there, but you should be selecting the article you're after through the query. Something like this:

 

$sql = "SELECT id, post FROM articles WHERE id='" . mysql_real_escape_string($_GET['article']) . "'";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_assoc($result);
echo $r['post'];

 

mysql_real_escape_string

 

That's just an example of how to fetch the data. In your actual application you'll probably want some checking to make sure that an article exists and if it doesn't show some error.

 

Oh, and using shorttags is never a good idea.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.