Jump to content
xisto Community
eskimmer

Using Multiple Selection Array In Table To Order Data Using multiple selection array in table to order data

Recommended Posts

have a form that has a multiple select choice, like this:

<form method="post" action="display.php"<select multiple name="selectsort[]"><option value="code">Code</option><option value="amount">Amount</option><option value="dateammended">Date Ammended</option><option value="expreviewdate">Expiration/Review Date</option><option value="effectivedate">Effective Date</option><option value="expired">Expired</option><option value="team">Issuing Team</option><option value="originate">OSL Originate</option></select></form>

The display.php file runs a query that sorts the results based on the selection (sometimes multiple) made in the form. The display.php file looks something like this:

$selectsort = $_POST['selectsort'];if( isset( $_POST['selectsort'] )) {$query = "SELECT * FROM contracts ORDER BY '{$_POST['selectsort']}' DESC";}$result = mysql_query($query);

I then echo the information in a table. I get results, but it doesn't pay attention to multiple selections. It only orders by the last selection made.

 

I can echo out the various selections and can see that the select part is working.

echo "$selectsort[0] , $selectsort[1] , $selectsort[2], ........"
How can use the selectsort[] array to order by the multiple selections?

 

Notice from Plenoptic:
ALL code posted must be put into [ CODE ] tags. Please review the Xisto ReadMe for more rules and guidelines as to not receive warnings.

Share this post


Link to post
Share on other sites

Try this one. The while statement continually queries in the database while there are query results then prints the results in the screen using echo.

 

if( isset( $_POST['selectsort'] )) {	$query = "SELECT * FROM contracts ORDER BY '{$_POST['selectsort']}' DESC";	$result = mysql_query($query);	while($result_rows = mysql_fetch_row($result)){		echo 'field 1 value: '.$result_rows[0];		echo 'field 2 value: '.$result_rows[1];		echo 'field 3 value: '.$result_rows[2];	}}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.