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