Jump to content

[SOLVED] Selecting what to sort by


Suchy

Recommended Posts

I want to make a pulldown menu where the user can select how to sort and display info from MySQL. (by date, name...)

 

So far I have this, but it is not working.

 

...

// connect to database

connectDB();

if(in("Sort"))

{

$sort =($_POST['sort']);

$query = "SELECT * FROM entries ORDER BY 'sort'";

} else

$query = "SELECT * FROM entries ORDER BY 'time'";

 

$result = mysql_query($query);

$entriesResults = getRows($result);

 

...

 

...

<form id="sort" method="POST" action="<?php $_SERVER['PHP_SELF']?>">

                Sort By  :<br />

                  <select name="sort">

                    <option value="date" selected>Date Submited</option>

                    <option value="name" selected>Name</option>

                    <option value="service">Service</option>

                    <option value="os">OS</option>

                  </select>

                  <input name="Sort" type="submit" id="Sort" value="Sort" />

</form>

...

 

Can someone please tell me where I am going wrong, or maybe point me to some kind of tutorial on this topic.

 

The fields in the database have the names: date, name, service, os

Link to comment
https://forums.phpfreaks.com/topic/46220-solved-selecting-what-to-sort-by/
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.