SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member TwoWorlds's Avatar
    Join Date
    Jan 2006
    Location
    Hertfordshire, UK
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help (Easy?): Let the user sort my video list?

    Hey there,

    I hope this is the right forum (after reading the "where to" I think this is right)..

    Anyway, I am running a video website using a script. This script includes modules, which are basically PHP to show the video list and such.

    Basically my videos are taken from the database and displayed by the date added. Using this code.. (I have ommitted some code from above hope this doesnt confuse people)..

    PHP Code:
        $db->query("SELECT * FROM `videos` WHERE `kategorie` = '" $catid "' " $plist " AND `status` = 'true' ORDER BY `kategorie`, `[B]added[/B]` DESC");
        
        
    $count $db->numRows();
        
    $resV $db->fetchAll();
        if(isset(
    $_GET['page']))
              
    $output displayVideos($resV,$_GET['page'],$thisurl);
          else
              
    $output displayVideos($resV,1,$thisurl);
        echo 
    $output
    What I want is my user to press a text link at the top of the page to order the videos in another way. Like below for example ..

    PHP Code:
        $db->query("SELECT * FROM `videos` WHERE `kategorie` = '" $catid "' " $plist " AND `status` = 'true' ORDER BY `kategorie`, `[B]visits[/B]` DESC");
        
        
    $count $db->numRows();
        
    $resV $db->fetchAll();
        if(isset(
    $_GET['page']))
              
    $output displayVideos($resV,$_GET['page'],$thisurl);
          else
              
    $output displayVideos($resV,1,$thisurl);
        echo 
    $output
    The problem I am having when trying to learn PHP is how to get the link to reload the page and replace that word with another, or switch to the second code?

    Ive tried everything to my knowledge which is very limited.

    Any help would be great

    Dean

  2. #2
    SitePoint Enthusiast monkey56657's Avatar
    Join Date
    Jun 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $db->query("SELECT * FROM `videos` WHERE `kategorie` = '" $catid "' " $plist " AND `status` = 'true' ORDER BY `kategorie`, `".mysql_real_escape_string($_GET['Order'])."` DESC");

        
    $count $db->numRows();

        
    $resV $db->fetchAll();

        if(isset(
    $_GET['page']))

              
    $output displayVideos($resV,$_GET['page'],$thisurl);

          else

              
    $output displayVideos($resV,1,$thisurl);

        echo 
    $output
    then at the top have links like...

    <a href="?Order=added">Sort By Date Added</a>
    <a href="?Order=visits>Sort By No Of Visits</a>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would change the query to use a get variable for sorting the list and set the links for sorting like so:

    <a href=". . . ?sort=xxx">Different Sort Link</a>

    Next, write the conditional:

    if (!isset $_GET[sort]){
    $query = "default query here";
    }
    else {
    $query = "query with ORDER BY $_GET[sort]";
    }

    Finally, be sure you've escaped your query or you might have some security problems.

    This will reload the page when the user clicks the link, and change the sort order of the list.

    J.
    Radioactive chicken gave me gay.
    Neonbrainiac

  4. #4
    SitePoint Member TwoWorlds's Avatar
    Join Date
    Jan 2006
    Location
    Hertfordshire, UK
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thank you both for your help firstly

    Unfortunately neither worked yet :S..

    I think the problem may be that the file im editing is called "list.module" this is included by "content.module" so when refreshing is it refreshing this module?

    Both worked until I click the link, they refresh but no order has been changed.

    Any ideas?

    Dean


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
  •