Jump to content

query order using get


doddsey_65

Recommended Posts

I am attempting to order the results of a query using the get value but they wont order.

 

here is the form:

 

echo "<form name=\"order_form\" action=\"{$site_root}/index.php\" method=\"GET\">";
echo "<input type=\"hidden\" value=\"{$forum_id}\" name=\"forum\" />";

echo "<select name=\"order_by\" style=\"margin-left:5px;\">";
echo "<option value=\"asc\" name=\"order_option\" />Order By: Ascending</option>";
echo "<option value=\"desc\" name=\"order_option\" />Order By: Descending</option>";
echo "</select>";

echo "<select name=\"sort_by\" style=\"margin-left:5px;\">";
echo "<option value=\"topic_name\" name=\"sort_option\" />Sort By: Topic Name</option>";
echo "<option value=\"topic_poster\" name=\"sort_option\" />Sort By: Topic Author</option>";
echo "<option value=\"topic_time_posted\" name=\"sort_option\" />Sort By: Time Posted</option>";
echo "<option value=\"topic_views\" name=\"sort_option\" />Sort By: Topic Views</option>";
echo "<option value=\"topic_replies\" name=\"sort_option\" />Sort By: Topic Replies</option>";
echo "<option value=\"topic_last_poster\" name=\"sort_option\" />Sort By: Last Poster</option>";
echo "<option value=\"topic_last_post_time\" name=\"sort_option\" />Sort By: Last Post Time</option>";
echo "</select>";

echo "<input type=\"submit\" value=\"Order\" />";
echo "</form>";

 

here is the query:

 

$topic_info_query = $db->query("SELECT 
								f.forum_id, f.forum_name,
								m.user_id, m.user_username, m.user_group,
								t.thread_topic_id, t.topic_name, t.topic_poster, t.topic_time_posted, t.topic_views,
								t.topic_replies, t.topic_last_poster, t.topic_last_post_time, t.topic_locked,
								t.topic_sticky, t.topic_edited, t.topic_last_poster_id, t.topic_last_poster_group,
								t.topic_icon
								FROM ".DB_PREFIX."topics as t

								LEFT JOIN ".DB_PREFIX."members as m
								ON t.topic_poster = m.user_username

								LEFT JOIN ".DB_PREFIX."forums as f
								ON t.forum_id = f.forum_id

								WHERE t.forum_id = '$forum_id'
								'".$sort_by . ' ' . $order_by."'")

 

and here is where $sort_by and $order_by are defined:

 

if (isset($_GET['order_by']))
{
$order_by = mysql_real_escape_string($_GET['order_by']);
$order_by = strtoupper($order_by);
}

if (isset($_GET['sort_by']))
{
$sort_by = 'ORDER BY t.'.mysql_real_escape_string($_GET['sort_by']);
}

 

when i echo '".$sort_by . ' ' . $order_by."' which is how it appears in the query i get:

 

t.topic_last_post_time DESC

 

which is exactly right. But the results are not being sorted. The echoed variables change as does the url but no sorting happens.

 

any ideas?

 

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.