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
https://forums.phpfreaks.com/topic/78933-php-category-sorter/
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
https://forums.phpfreaks.com/topic/78933-php-category-sorter/#findComment-399448
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
https://forums.phpfreaks.com/topic/78933-php-category-sorter/#findComment-399470
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.