Question: Sorting through table headers?
Question: Sorting through table headers?
am 13.09.2009 13:55:41 von Parham Doustdar
------=_NextPart_000_00CD_01CA348E.D60B0FD0
Content-Type: text/plain;
charset="windows-1256"
Content-Transfer-Encoding: quoted-printable
Hello there,
I've been asked to create something like the tables you usually see, =
where the headers are actually links and when you click the links, the =
table gets sorted based on the header. Are there any classes that you =
know of that would do the job? My current idea is to return an array of =
the colomn which contains the data you want to sort on (like 'name') =
then sort the array and do something like:
[code]
for (i =3D 0; i < length(array); i++)
mysql_query("select * from table where 'name' =3D ${aray[i]}");
[/code]
Any better algorithms anyone?
Thanks!
--=20
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
GoogleTalk: parham90@gmail.com
Twitter: PD90
email: parham90 at GMail dot com
------=_NextPart_000_00CD_01CA348E.D60B0FD0--
Re: Question: Sorting through table headers?
am 14.09.2009 04:28:56 von Tommy Pham
--- On Sun, 9/13/09, Parham Doustdar wrote:
> From: Parham Doustdar
> Subject: [PHP] Question: Sorting through table headers?
> To: php-general@lists.php.net
> Date: Sunday, September 13, 2009, 6:55 AM
> Hello there,
> I've been asked to create something like the tables you
> usually see, where the headers are actually links and when
> you click the links, the table gets sorted based on the
> header. Are there any classes that you know of that would do
> the job? My current idea is to return an array of the colomn
> which contains the data you want to sort on (like 'name')
> then sort the array and do something like:
> [code]
> for (i = 0; i < length(array); i++)
> mysql_query("select * from table where 'name' =
> ${aray[i]}");
> [/code]
Your code looks like you're filtering and not sorting. You should revisit the basics of SQL syntax.
> Any better algorithms anyone?
> Thanks!
> --
> ---
> Contact info:
> Skype: parham-d
> MSN: fire_lizard16 at hotmail dot com
> GoogleTalk: parham90@gmail.com
> Twitter: PD90
> email: parham90 at GMail dot com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Question: Sorting through table headers?
am 14.09.2009 09:09:18 von List Manager
Parham Doustdar wrote:
> Hello there,
> I've been asked to create something like the tables you usually see, where the headers are actually links and when you click the links, the table gets sorted based on the header. Are there any classes that you know of that would do the job? My current idea is to return an array of the colomn which contains the data you want to sort on (like 'name') then sort the array and do something like:
> [code]
> for (i = 0; i < length(array); i++)
> mysql_query("select * from table where 'name' = ${aray[i]}");
> [/code]
> Any better algorithms anyone?
> Thanks!
My suggestion would be to have the client do it.
http://www.js-vault.us/iscripts/007.html
I use it on a number of different pages.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Question: Sorting through table headers?
am 14.09.2009 11:55:20 von gonatan
Jim Lucas wrote:
> Parham Doustdar wrote:
>> Hello there,
>> I've been asked to create something like the tables you usually see,
>> where the headers are actually links and when you click the links, the
>> table gets sorted based on the header. Are there any classes that you
>> know of that would do the job? My current idea is to return an array
>> of the colomn which contains the data you want to sort on (like
>> 'name') then sort the array and do something like:
>> [code]
>> for (i = 0; i < length(array); i++)
>> mysql_query("select * from table where 'name' = ${aray[i]}");
>> [/code]
>> Any better algorithms anyone?
>> Thanks!
>
> My suggestion would be to have the client do it.
>
> http://www.js-vault.us/iscripts/007.html
>
> I use it on a number of different pages.
This could be done clientside if you intend to show all data. If you
want to implement paging too, you have to do it on the server though.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Question: Sorting through table headers?
am 14.09.2009 12:49:55 von Tony Marston
What you are trying to do is ridiculously easy, and something which I
accomplished years ago. Basically every column heading needs to be output as
a hyperlink which repeats the current page with the addition of
"orderby=" in the URL. This information appears in the $_GET
array, so you just repeat the previous sql query with the addition of an
ORDER BY clause.
This assumes that you have already taken care of caching the query and
paginating the results.
You cannot do this in a separate class as it requires action in both the
presentation (UI) and data access layers, and a single class is not allowed
to operate in more than one layer.
--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
""Parham Doustdar"" wrote in message
news:77.26.26879.9B9ADAA4@pb1.pair.com...
Hello there,
I've been asked to create something like the tables you usually see, where
the headers are actually links and when you click the links, the table gets
sorted based on the header. Are there any classes that you know of that
would do the job? My current idea is to return an array of the colomn which
contains the data you want to sort on (like 'name') then sort the array and
do something like:
[code]
for (i = 0; i < length(array); i++)
mysql_query("select * from table where 'name' = ${aray[i]}");
[/code]
Any better algorithms anyone?
Thanks!
--
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
GoogleTalk: parham90@gmail.com
Twitter: PD90
email: parham90 at GMail dot com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Question: Sorting through table headers?
am 14.09.2009 21:29:15 von gonatan
Tony Marston wrote:
> You cannot do this in a separate class as it requires action in both the
> presentation (UI) and data access layers, and a single class is not allowed
> to operate in more than one layer.
You can, but you shouldn't if you want to write your classes according
to the MVC pattern.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Question: Sorting through table headers?
am 14.09.2009 21:57:33 von Phpster
On Mon, Sep 14, 2009 at 3:29 PM, Marcus Gnaß wrote:
> Tony Marston wrote:
>
>> You cannot do this in a separate class as it requires action in both the
>> presentation (UI) and data access layers, and a single class is not allo=
wed
>> to operate in more than one layer.
>
> You can, but you shouldn't if you want to write your classes according
> to the MVC pattern.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Why not send the data as XML and let the client handle it? Sorting and
the filtering are relatively simple to implement in JS
--=20
Bastien
Cat, the other other white meat
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Question: Sorting through table headers?
am 14.09.2009 21:58:01 von Phpster
On Mon, Sep 14, 2009 at 3:57 PM, Bastien Koert wrote:
> On Mon, Sep 14, 2009 at 3:29 PM, Marcus Gnaß wrote:
>> Tony Marston wrote:
>>
>>> You cannot do this in a separate class as it requires action in both th=
e
>>> presentation (UI) and data access layers, and a single class is not all=
owed
>>> to operate in more than one layer.
>>
>> You can, but you shouldn't if you want to write your classes according
>> to the MVC pattern.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
> Why not send the data as XML and let the client handle it? Sorting and
> the filtering are relatively simple to implement in JS
> --
>
> Bastien
>
> Cat, the other other white meat
>
Make that send ALL the data
--=20
Bastien
Cat, the other other white meat
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Question: Sorting through table headers?
am 17.09.2009 20:08:27 von Parham Doustdar
Hello there,
Thanks a lot. The Javascript class worked like a charm. I'm glad I asked! :)
Thanks for all the answers, everyone. I seem to have communicated my intent
wrong, when it came to my algorithm, but basically, yes, it was not based on
the MVC model, and yes, it did filter the SQL table, then sorted them and
displayed each row according to the ID, for example, of the different things
in the SQL table. In other words, let's say that I wanted to get the ID,
sort the array containing the ID's, then show the rows of the table by
looping through the array and showing each row of the table.
However, the javascript did what I wanted perfectly anyway. I have to read
up more on Javascript since I seem to have an awful understanding of it, but
for now... *phew* hehe!
--
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
GoogleTalk: parham90@gmail.com
Twitter: PD90
email: parham90 at GMail dot com
"Jim Lucas" wrote in message
news:4AADEC1E.60000@cmsws.com...
> Parham Doustdar wrote:
>> Hello there,
>> I've been asked to create something like the tables you usually see,
>> where the headers are actually links and when you click the links, the
>> table gets sorted based on the header. Are there any classes that you
>> know of that would do the job? My current idea is to return an array of
>> the colomn which contains the data you want to sort on (like 'name') then
>> sort the array and do something like:
>> [code]
>> for (i = 0; i < length(array); i++)
>> mysql_query("select * from table where 'name' = ${aray[i]}");
>> [/code]
>> Any better algorithms anyone?
>> Thanks!
>
> My suggestion would be to have the client do it.
>
> http://www.js-vault.us/iscripts/007.html
>
> I use it on a number of different pages.
> --
> Jim Lucas
>
> "Some men are born to greatness, some achieve greatness,
> and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
> by William Shakespeare
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php