Posted by _lithium Tue 27th Feb 2007 18:25 - Syntax is PHP - 53 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers
PHP parser reported no syntax errors in this post!
  1. class Stupidsortproblem{
  2.    
  3.    public $sortBy;
  4.    public $sortDir;
  5.    public $limit;
  6.    
  7.    public $query;
  8.    public $debug = false;
  9.    
  10.    public $thArray = array('Movie Title' => 'title',
  11.                            'Dice Rate'   => 'rate',
  12.                            'Genre'       => 'genre',
  13.                            'Seen'        => 'seen');
  14.    function __construct(){
  15.       $this->pull_GET_Vars();
  16.       $this->craft_Query();
  17.       $this->result = mysql_query($this->query);
  18.       if($this->debug === true){
  19.          if(!$this->result){ print $this->query; }
  20.       }
  21.       $this->display_Results();
  22.    }
  23.    
  24.    function pull_GET_Vars(){
  25.       $this->sortBy  = (isset($_GET['sort'])   && !empty($_GET['sort']))    ? $_GET['sort'] : false;
  26.       $this->sortDir = (isset($_GET['sortdir'])&& !empty($_GET['sortdir'])) ? $_GET['sortdir'] : 'asc';
  27.       $this->limit   = (isset($_GET['limit'])   && is_numeric($_GET['limit'])) ? $_GET['limit'] : 100;
  28.    }
  29.    
  30.    
  31.    function craft_Query(){
  32.       $this->query = "SELECT
  33.                       id,
  34.                       overview,
  35.                       title,
  36.                       rate,
  37.                       genre,
  38.                       seen
  39.                       FROM
  40.                       log
  41.                       ";
  42.       if($this->sortBy !== false){
  43.          $this->query .= "
  44.                           ORDER by {$this->sort} {$this->sortDir}
  45.                           ";
  46.       }
  47.       $this->query .= " LIMIT {$this->limit} ";
  48.    }
  49.    
  50.    function display_Resutls(){
  51.  
  52.       $displayDir = ($this->sortDir == 'asc') ? 'desc' : 'asc';
  53.  
  54.       $html       = '
  55. ';   
  56.       foreach($this->thArray as $displayName => $columnName){
  57.          $fontWeight = ($columnName == $this->sortBy) ? 'bold' : 'normal';
  58.          $html .= '
  59.                   ';
  60.       }
  61.       while($obj = mysql_fetch_object($this->result)){
  62.          $html .= '
  63.                  
  64.                      
  65.                   ';
  66.       }
  67.       $html .= '
  68. $fontWeight.';">';
  69.          $html .= '
    \'pointer\'
  70.                         onclick="document.href=\'?sort='.$columnName.'&sortdir='.$displayDir.'\'">
  71.                            '.$displayName.'
  72.                    
  73.                    
  74. '.$obj->title.'
  75.                      
  76. '.$obj->rate.'
  77.                      
  78. '.$obj->genre.'
  79.                      
  80. '.$obj->seen.'
  81.                  
  82. '
    ;
  83.       return print($html);
  84.    }
  85. }
  86.  
  87.  

PermaLink to this entry https://pastebin.co.uk/11084
Posted by _lithium Tue 27th Feb 2007 18:25 - Syntax is PHP - 53 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers

 

Comments: 0