SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member esammons's Avatar
    Join Date
    Sep 2004
    Location
    Virginia
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating "hot spots" in columns, sort on click

    I have never tried this before in PHP, nor do I believe I even have the terminology correct so I thought I would seek the advice of those with stronger foo.

    I would like to make my column headings in a table "hot" so that when a user selects (clicks on) a given heading the contents of the table will be sorted based on that column.

    What is the recommended way for handling this desired functionality? I would prefer a non-javascript solution, first my javascript foo is not very strong at all and second we are not big on javascript around here.

    Any and all suggestions are welcome.

    Thanks!

  2. #2
    SitePoint Zealot romance's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could do something like the following:

    for the each of the columns headings add something like nameofyourfile.php?sort=columnName&order=asc

    your SQL statement would then be affected by the querystring such like the following:

    if ($HTTP_GET['columnName'] =="") // if there is no sort querystring then just do a normal statment
    {
    $SQL = "select * from tablename ";
    }
    else // otherwise sort by querystring
    {
    $SQL = "select * from tablename order by ".$HTTP_GET['columnName']." ".$HTTP_GET['order'];
    }

    that could be used as a basis. Remember however that your letting users alter SQL statement with querystrings so you should take precautions in making sure that no malicous code is used

  3. #3
    SitePoint Member esammons's Avatar
    Join Date
    Sep 2004
    Location
    Virginia
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was hoping to do this with a POST only, no gets. And to be sure I am clear on what I am looking for, as I have never done this before, I would like to create a link or button in the column headings that when clicked will cause the column to sort based on that.

    I have thinking about using an array to hold the results so that I don't have to execute the sql again; however, there is the chance that this array could be large -- real large.

    Also, I personally have never executed php code by any means other than a button. Is there a way to execute php code by simply clicking a LINK?

    Thanks!

  4. #4
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    POST would be a really bad idea IMO. You could do it i suppose, but it would make it so if you ever pressed back, you'd get a page expired error. I've never seen a column sorting script that used anything but GET.

  5. #5
    SitePoint Member esammons's Avatar
    Join Date
    Sep 2004
    Location
    Virginia
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would I do this with GET? and again, without Javascript. I am open to the idea of using GET, I tend to avoid GET where it may get me into trouble with long urls by passing variables.

    thanks!

  6. #6
    SitePoint Zealot lemkepf's Avatar
    Join Date
    Feb 2002
    Location
    WI, USA
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make the column heading regular links. you'd have something like:
    HTML Code:
    <a href="nameofyourfile.php?sort=columnName&order=asc">Column Name</a>
    Then do as romance said and create the SQL based on the $_GET['sort'] and $_GET['order'].
    Happiness is a belt-fed weapon
    Consciousness: That annoying time between naps.
    Modevia Web Services LLC.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •