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 ...
}