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
https://forums.phpfreaks.com/topic/239482-help-giving-article-its-own-url/
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.

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.