Home > Category Listing "; $header_code = ''; // prevent loading without a page $use_header = '1'; $connectdb = '1'; // get config file include('config.php'); /////////////////////////////////////////// $mquery = "SELECT * FROM game_cat"; $mresult = mysqli_query($dbcon, $mquery, $db); $mquery_data = mysqli_fetch_row($mresult); print "\n"; /////////////////////////////////////////// // for pagination if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; // restrict data type for var $pageno = preg_replace('/([^0-9])/', "", $pageno); } else { $pageno = 1; } // set up random icon picking range($start,$stop); $rand_set = range(1,50); shuffle($rand_set); shuffle($rand_set); $max_icons_available = 104; // init the counter $rand_cntr = 1; // how many items to display? // total is max_across * max_down $max_across = 2; $max_down = 8; $max_items = ($max_across * $max_down); // set title $titlebar_text = "Jokes'nFun.com - Game Categories"; $title_text = "Flash Game Categories"; $intro_text = "Please feel free to bowse our great selection of games!"; include('/var/www/jokesnfun.com/web/header.php'); include('/var/www/jokesnfun.com/web/games/topmenu.php'); print <<$title_text $intro_text

EOM; $cat_id = trim($_REQUEST['cid']); // clean up data // restrict data type for var $cat_id = preg_replace('/([^0-9])/', "", $cat_id); if($cat_id == "" || $cat_id > 50){ // print the default list //printCategoryList(); // print the menu blob generated in the header print "\n

    \n$menu_blob
\n"; }else{ // display the category $query ="SELECT * FROM game_cat WHERE cat_id = '$cat_id'"; $result = mysqli_query($dbcon, $query ,$db); $myrow = mysqli_fetch_array($result); $cat_name = trim($myrow['cat_name']); // update path_var $path_var = $path_var . $cat_name; // how many items to display? // total is max_across * max_down $max_across = 2; $max_down = 10; $max_items = ($max_across * $max_down); ///////////////////////////////////////////// // // pagination $pquery = "SELECT count(*) FROM game_list WHERE category = '$cat_id' AND enabled = '1'"; $result = mysqli_query($dbcon, $pquery, $db); $query_data = mysqli_fetch_row($result); $numrows = $query_data[0]; //print "NUMROWS: $numrows
"; //3. Calculate number of $lastpage //This code uses the values in $rows_per_page and $numrows in order to identify the number of the last page. $rows_per_page = 30; $lastpage = ceil($numrows/$rows_per_page); //4. Ensure that $pageno is within range //This code checks that the value of $pageno is an integer between 1 and $lastpage. $pageno = (int)$pageno; if ($pageno < 1) { $pageno = 1; } elseif ($pageno > $lastpage) { $pageno = $lastpage; } // if //5. Construct LIMIT clause //This code will construct the LIMIT clause for the sql SELECT statement. $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; //print "LIMIT: $limit
"; //6. Issue the database query //Now we can issue the database qery and process the result. $query = "SELECT * FROM game_list WHERE category = '$cat_id' AND enabled = '1' $limit"; $result = mysqli_query($dbcon, $query, $db); ////////////////////////////////////// // No results? if($numrows == 0){ print "Sorry, there are no games in this category at this time."; print <<

EOM; // get footer include('/var/www/jokesnfun.com/web/footer.php'); exit; } //print "Q1: $query
"; //$query = "SELECT * FROM game_list WHERE category = '$cat_id' AND enabled = '1' LIMIT $max_items"; //$result = mysqli_query($dbcon, $query, $db); //print "Q2: $query
"; $cellcounter = 0; print_nav(); print <<  $cat_name EOM; while ($myrow = mysqli_fetch_array($result)) { // get the vars $game_id = trim($myrow['game_id']); $display_name = trim($myrow['display_name']); $image_name = trim($myrow['image_name']); $times_played = trim($myrow['times_played']); $rating = trim($myrow['rating']); $ratimg = round($rating) . "stars"; $display_name = preg_replace('|-|', ' ', $display_name); // correct for missing icons if($image_name == "stand_in.jpg"){ $image_name = image_picker(); } print <<
$display_name

Played $times_played times
EOM; $cellcounter++; $itemcounter++; if($cellcounter == $max_across){ print "\n"; $cellcounter = 0; if($itemcounter != $max_items){ print "\n"; } } } if($cellcounter == '1'){print "  ";} if($cellcounter == '2'){print " ";} print "\n"; // print pagination links print_nav(); } ///////////////////////////////////// function printCategoryList(){ print "Z $menu_blob "; } print <<

EOM; // get footer include('/var/www/jokesnfun.com/web/footer.php'); ///////////////////////////////////////////// function print_nav(){ global $cat_id, $prevpage, $pageno, $lastpage, $nextpage; print "
"; // Construct pagination hyperlinks // construct the hyperlinks which will allow the user to select // other pages. We start with the links for any previous pages. if ($pageno == 1) { echo " First Prev "; } else { echo " << First "; $prevpage = $pageno-1; echo " < Prev "; } // inform the user of his current position in the sequence of available pages. echo " ( Page $pageno of $lastpage ) "; // This code will provide the links for any following pages. if ($pageno == $lastpage) { echo " Next Last "; } else { $nextpage = $pageno+1; echo " Next > "; echo " Last >> "; } print "
"; } ///////////////////////////////////////////// function image_picker(){ // selects an icon for games without an image global $image_name, $rand_set, $max_icons_available, $start, $stop, $rand_cntr; $rand_image = $rand_set[$rand_cntr]; $rand_cntr++; // check to make sure we didn't run out of numbers // if so, refresh the rand_set array if($rand_cntr){ // create a new array range($start,$stop); // fill it $rand_set = range(1,$max_icons_available); // 50 icons available // randomize it shuffle($rand_set); shuffle($rand_set); // reset the counter $rand_cntr = 1; } $image_name = "stand_in$rand_image.jpg"; return $image_name; } ?>