Jump to content

php category sorter?


[-_-]

Recommended Posts

How would I make a category field like this? http://thepiratebay.org/browse/200

I want one just for displaying external site links on my main page so people can sort from the site with the highest rating to the lowest rating and sort by what torrents they specialize in. Would I need to use mysql for this?

 

Sorry if thats not the right name for this sort of thing I'm a total noob at php. ;D

Link to comment
Share on other sites

You simply pass the field to sort by through the url, then place that in your query. Something like....

 

<?php

  if (isset($_GET['sortby'])) {
    $sort = $_GET['sortby'];
  } else {
    // set a default
    $sort = 'fld1';
  }

  if (isset($_GET['order'])) {
    $order = $_GET['order'];
  } else {
    $order = 'DESC';
  }

  $sql = "SELECT * FROM tbl ORDER BY $sort $order;

?>

Link to comment
Share on other sites

Yeah there is an error on the last line, should be....

 

$sql = "SELECT * FROM tbl ORDER BY $sort $order";

 

Anyway, this is not complete, working code. Its just an example of how to dynamically create the query required.

 

Sounds like you might need to do some tutorials on database access first. Theres a good link in my signiture which has an entire chapter dedicated to the subject.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.