View Single Post
Old 01-15-2013, 11:55 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,188
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Okay...I do *NOT* code in PHP. So don't be surprised if I make some PHP typos in this.

But here's roughly how I would do it:
Code:
<?
include ("config_file.php");
include(DIR_LNG.'top_random_jokes.php');
$type = TEXT_RANDOM_JOKES_ON." ";  // no idea what this is for
           
$jtype = $_GET["jtype"];
if ( ! isset($jtype) ) { $jtype = "random"; }
if ( $jtype == "random" ) { $ordering = " RAND( )"; }
else if ( $jtype == "ten" ) { $ordering = " rating_value DESC"; }
else { $ordering = " emailed_value DESC"; }

$cat_id = $_REQUEST["cat_id"]; // why would this ever NOT be $_GET??  oh, well

$condition = " WHERE validate = 1 AND slng = '$slng' "; // where does $slng come from???
if(isset($cat_id) && 1 * $cat_id != 0) 
{
    $condition .= " AND category_id=" . (1 * $cat_id) ;
}
// You should NEVER use SELECT * but I have to use it here 
// because you didn't show what the fields in your DB table are
$SQL = "SELECT * FROM `$bx_db_table_jokes` " . $condition . " ORDER BY $ordering LIMIT 10";

$result = mysql_query($SQL) or die( mysql_error() );
while ( $row = mysql_fetch_array($result) )
{
    ... show one joke ...
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote