Jump to content

ORDER BY question


bigggnick

Recommended Posts

Hey all,

 

I'm making a system for managing articles on my site, and I was wondering if i could do a line like this:

  $result = mysql_query("SELECT article_content, auth_name FROM articles WHERE article_name='$article_name' ORDER BY article_name");
  while($row = mysql_fetch_array($result, MYSQL_BOTH)){
echo '<h1>' . $row[article_name] . '</h1>';
echo 'By:' . $row[auth_name];
echo $row[article_content];

 

an example of the URL would be articles.php?article_name=test

 

Would this work?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/68925-order-by-question/
Share on other sites

If you are send the information through the $_GET method you will need to first pull it out into a variable.

 

$article_name = $_GET['article_name'];

$result = mysql_query("SELECT article_content, auth_name FROM articles WHERE article_name='" . $article_name . "' ORDER BY '" . $article_name . "'");
  while($row = mysql_fetch_array($result, MYSQL_BOTH)){
echo '<h1>' . $article_name . '</h1>'; // to use the $row[article_name] here you need to request article_name in your query
echo 'By:' . $row[auth_name];
echo $row[article_content];
}

 

I did not test this code, but the basics are that you first need to get the data from the URL before using it in the query.

Link to comment
https://forums.phpfreaks.com/topic/68925-order-by-question/#findComment-346466
Share on other sites

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.