FatDank Posted June 15, 2011 Share Posted June 15, 2011 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/239482-help-giving-article-its-own-url/ Share on other sites More sharing options...
Alex Posted June 16, 2011 Share Posted June 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239482-help-giving-article-its-own-url/#findComment-1230306 Share on other sites More sharing options...
FatDank Posted June 16, 2011 Author Share Posted June 16, 2011 Thanks mate. Works great. About the error page would it be something like <? else { echo mysql_error() } ?> Quote Link to comment https://forums.phpfreaks.com/topic/239482-help-giving-article-its-own-url/#findComment-1230426 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.