www.webdeveloper.com
Results 1 to 3 of 3

Thread: Using onlick for list option

  1. #1
    Join Date
    Nov 2009
    Posts
    5

    Using onlick for list option

    Hi All,

    I am currently looking to insert a small list that allows the user to sort search results on my site like "Price: High to Low" etc.

    I know that you can include a button and sort the listings that way but I want the listings to be sorted(Page reloaded with amended sql statement) when the user selects their chosen sorting option.

    So probably going to pass the value to a function which reconstructs the URL and then need to load that URL.

    Any ideas whether you can use the onclick function to firstly pass the value to a function and then reload the page that has been sorted?

  2. #2
    Join Date
    Nov 2009
    Posts
    9
    Not sure i understand what you meen but you can use:

    HTML Code:
    <ul>
    	<li onClick="location.href='searchpage.php?sort=name DESC';">Sort by name desc</li>
        <li onClick="location.href='searchpage.php?sort=id DESC';">Sort by id desc</li>
    </ul>
    PHP Code:
    <?php
    $sort 
    $_GET['sort'];
    $search_query mysql_query("SELECT * FROM `$mysql_database`.`sometable` WHERE id!='' ORDER BY $sort");
    while(
    $out mysql_fetch_object($search_query)){
        echo 
    "$out->name &nbsp; &nbsp; $out->id";
    }
    ?>
    Hope this helps, if not, ill help some more
    Just describe a bit more (a)

    Kris

  3. #3
    Join Date
    Nov 2009
    Posts
    9

    Talking

    If you want to etc have sort=1d as name DESC you can use something like this insted

    PHP Code:
    <ul>
        <
    li onClick="location.href='searchpage.php?sort=1d';">Sort by name desc</li>
        <
    li onClick="location.href='searchpage.php?sort=2d';">Sort by id desc</li>
    </
    ul
    PHP Code:
    <?php
    $sort 
    $_GET['sort'];

    if(
    $sort == "1d"){
        
    $sort_option "ORDER BY name DESC";
    }

    elseif(
    $sort == "2d"){
        
    $sort_option "ORDER BY id DESC";



    $search_query mysql_query("SELECT * FROM `$mysql_database`.`sometable` WHERE id!='' $sort_option");
    while(
    $out mysql_fetch_object($search_query)){
        echo 
    "$out->name &nbsp; &nbsp; $out->id";
    }
    ?>
    Maybe that was better?
    Still dont really know what you want
    But might give you an idea?

    Kris

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles