p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Change the data order click event


Message #1 by "Vikas Athavale" <vikaspa@b...> on Fri, 27 Sep 2002 04:40:31
Dear All,

Please help me !!

I want to sort the data displayed on web page on click of button.

I have say
Name
Department
Salary
Grade

I hav a combo in which all user have to select the sort order in which he 
wants to see the data...(The combo box or drop down box contains 
values "Name, Department Salary and Grade)

The user select the order  (say name) by clicking the combo box or drop 
down box. 

The moment the user releases the combo or drop down box, I want to refresh 
the page with new sort order.
Message #2 by "David Scott-Bigsby" <DScott-Bigsby@P...> on Fri, 27 Sep 2002 10:36:31 -0700
> I hav a combo in which all user have to select the sort order
> in which he
> wants to see the data...(The combo box or drop down box contains
> values "Name, Department Salary and Grade)
>
> The user select the order  (say name) by clicking the combo
> box or drop down box.
>
> The moment the user releases the combo or drop down box, I
> want to refresh the page with new sort order.

You want to do two things.

One is use the value of the combo box to determine the sort order. You 
haven't said where your data comes from, but if it's an SQL database, 
then use the 'ORDER BY' clause, with the field determined by the combo 
box value. (A switch statement would be appropriate here.)

The other is to refresh the page when the combo box value changes. 
That's client-side functionality, which is out of the realm of possibity 
for PHP . . . but not JavaScript. Place your combo box within  <FORM> 
tags, set the ACTION to be your PHP script and use the NAME tag so you 
can easily reference the FORM (let's call it 'Fred'). Then, on the 
onChange or onClick event for your combo box, call this bit of JS:

	this.document.forms['Fred'].submit()

This will trigger a submit, and the result can be a resorted page.

dsb

***************************************       
David Scott-Bigsby
Product Manager, Web Site and PEDN

PureEdge Solutions
The Leader in Secure XML e-Forms

v:250-708-8145  f:250-708-8010
1-888-517-2675   www.PureEdge.com
***************************************
Message #3 by "jorge" <jorge@d...> on Sun, 29 Sep 2002 09:55:35 -0500
Hi Vikas:
There are several ways To acomplish your task
You need define the event from which the page is refreshed
if you decide to use a button you use your solution would be like this
<select name="pls_order_by">
<option value="Name" selected>Name</option>
<option value="Department">Department</option>
<option value="Salary">Salary</option>
<option value="Grade">Grade</option>
</select>
now when the form is submited when the user clicks the submit button you
have a variable to be placed in your query
$query="SELECT  * FROM mytable ORDER BY $pls_order_by ";

now if you want to refresh the page without the user having to click a
button you need to use Javascript

you can use  the onChange event to do it

<select name="pls_order_by" Onchange="form.submit();">
this will work as if the user has clicked the submit button

Saludos from Mexico

Jorge Cordero



----- Original Message -----
From: "Vikas Athavale" <vikaspa@b...>
To: "beginning php" <beginning_php@p...>
Sent: Friday, September 27, 2002 4:40 AM
Subject: [beginning_php] Change the data order click event


> Dear All,
>
> Please help me !!
>
> I want to sort the data displayed on web page on click of button.
>
> I have say
> Name
> Department
> Salary
> Grade
>
> I hav a combo in which all user have to select the sort order in which he
> wants to see the data...(The combo box or drop down box contains
> values "Name, Department Salary and Grade)
>
> The user select the order  (say name) by clicking the combo box or drop
> down box.
>
> The moment the user releases the combo or drop down box, I want to refresh
> the page with new sort order.



  Return to Index