great progress...

Discussion in 'Programming' started by someone100, Nov 6, 2008.

  1. #1
    how can i change this script so i will able to search utf-8 string ( in utf-8 database which already changed ) ?
    my site : smgames.net
    search field on the left !

    
    
    
    
    $items_per_row=8;
    
    
    /*
    script: browse.php
    purpose: browsing script - this script handles all the browsing of the arcade games.
    copyright: copyright 2005-2008 phpArcadeScript & Scott Lewis. All Rights Reserved. You may modify this file for use on your
    					site running a licenced copy of phpArcadeScript.
    					You must not distribute this file or derivations of it.
    support: www.phparcadescript.com
    
    */
    
    // This determines if we are browsing by all games or a specific category. The first one
    // means since they isn't a category id specified we are going to browse all games
    
                  $template = file_get_contents("./templates/$template_directory/item.html");
                  
                  $maintemplate = file_get_contents("./templates/$template_directory/browse.html");
       
                  $template = universal_template_codes($template);
       
                  $maintemplate = universal_template_codes($maintemplate);
    
    
    if ($rewrite != '0')
    {
        if (!$browse_cat_name && !$searchterm)
        $browseby = "ORDER BY gametitle ASC";
       
        // Since a category id was supplied, we will browse all the games in the specific category
        elseif (!$browse_cat_name)
        {
        }
      
        else
        $browseby = "AND (category = $browse_cat_id $child_cat_ids) ORDER BY gametitle ASC";
    
    }
    
    else
    {
        if (!$cat && !$searchterm)
        $browseby = "ORDER BY gametitle ASC";
        
        // Since a category id was supplied, we will browse all the games in the specific category
        
        else
        $browseby = "AND (category = '$cat' $child_cat_ids) ORDER BY gametitle ASC";
    
    }
    
    if (!($limit)){
    $limit = $max_results;} // Default results per-page.
    if (!($page)){
    $page = 0;} // Default page value.
    if (!$searchterm)
    $sql_query = "SELECT * from games WHERE gamestatus = 1 $browseby";
    else
    $sql_query = "SELECT * from games WHERE gamestatus = 1 AND (gametitle LIKE \"%$searchterm%\" OR gamedesc LIKE  \"%$searchterm%\" OR gamekeywords LIKE \"%$searchterm%\" OR instructions LIKE \"%$searchterm%\" OR gamefile LIKE \"%$searchterm%\")";
    $numresults = mysql_query($sql_query); // the query.
    $numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
    
    
    if (!empty($searchterm)){
    // LOG SEARCH RESULTS
          $searchterm2 = strtolower($searchterm);
          
          $now = time();
          
          // If its already been searched for, then increase the number of searches by one
          $sql = "SELECT count(id) AS already_searched from searches WHERE searchterm = '$searchterm2'";
          //store the SQL query in the result variable
          $result = @mysql_query($sql);
          $i = mysql_fetch_array($result); 
          $already_searched = $i['already_searched']; 
    
          if ($already_searched > 0)
          $update_search = mysql_query("UPDATE searches
          set amount = amount + 1,
          results = '$numrows',
          date = '$now'
          where searchterm = '$searchterm2'");
          
          else
          $insert_search = mysql_query("INSERT into searches
          set amount = '1',
          date = '$now',
          searchterm = '$searchterm2',
          results = '$numrows'");
          
          // Now we need to get the search ID just IF SE FRIENDLY IS TURNED ON
                $search_query = "SELECT * FROM searches WHERE searchterm = '$searchterm2' LIMIT 1";
                //store the SQL query in the result variable
                $search_result = mysql_query($search_query);
                if(@mysql_num_rows($search_result))
                {
                //output as long as there are still available fields
                while($row = mysql_fetch_array($search_result))
                {
                $searchid = $row['id'];
                $searchterm = stripslashes($row['searchterm']);
                $searchlink = make_friendly($searchterm);
                }
                }
          
    // END SEARCH LOGGING
    }
    
    
    if ($numrows == 0){
      // If no games can be found, then it displays the following
      $content.="<div align=\"center\">No Games Listed</div>";
    }
    else{
            $pages = intval($numrows/$limit); // Number of results pages.
            
            // $pages now contains int of pages, unless there is a remainder from division.
            
            if ($numrows%$limit) {
            $pages++;} // has remainder so add one page
            
            $current = ($page/$limit) + 1; // Current page number.
            
            if (($pages < 1) || ($pages == 0)) {
            $total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
            
            else {
            $total = $pages;} // Else total pages is $pages value.
            
            $first = $page + 1; // The first result.
            
            if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
            $last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
             
            else{
            $last = $numrows;} // If last results page, last result equals total number of results.
            
            // Now we can display results.
            $results = mysql_query("$sql_query LIMIT $page, $limit");
            $number_of_results = 0;
            $number_of_results_adsense = 0;
            while ($data = mysql_fetch_array($results))
            {
                    $number_of_results++;
                    $rating = $data['rating'];
                    $number_of_votes = $data['totalvotes'];
                    $gamedesc = stripslashes($data['gamedesc']);
                    $gametitle = $data['gametitle'];
    
    
    
                    $gametitle = stripslashes($gametitle);
    		$title = make_friendly($gametitle);
    		if(strlen($gametitle)>10)
                    // $gametitle = substr($gametitle,0,7)."..";
    				$gametitle = mb_substr($gametitle,0,13,"utf-8")."..";
    
                    $gameid = $data['gameid'];
                    $timesplayed = $data['timesplayed'];
                    $gamelocation = $data['gamelocation'];
                    $iconlocation = $data['iconlocation'];
                    $gameicon = $data['gameicon'];
                    
                    $star = get_rating($rating,$number_of_votes,$base_url);
                    
                        
                    if ($iconlocation == 1)
                    $gameicon = $gameicon;
                    elseif (!empty($gameicon))
                    $gameicon = $base_url."games/images/".$gameicon;
                    
                    if (empty($gameicon))
                    $gameicon = $defaulticon;
                    
                    if ($rewrite ==0)
                    $gamelink = $base_url."index.php?action=playgame&gameid=".$gameid;
                    else
                    $gamelink = $base_url.$sedir."/".$gameid."/".$title;
            	   
         
                    $bodytags = array(
                    
                                "%display_game%", // Where the game will be displayed
                                "%gameid%", // ID for the Game
                                "%gamelink%", // URL to the game page
                                "%gametitle%", // Title of the Game
                                "%gamedescription%", // Description of the Game
                                "%gamekeywords%", // Keywords for the game
                                "%timesplayed%", // Times the game has been played
                                "%rating%", // Current Game Rating
                                "%gameicon%", // The Game Icon
                   
                    );
      
                   $bodyreplacements = array(
      
                                "$file_display", // Where the game will be displayed
                                "$gameid", // ID for the Game
                                "$gamelink", // URL to the game page
                                "$gametitle", // Title of the Game
                                "$gamedesc", // Description of the Game
                                "$gamekeywords", // Keywords for the game
                                "$timesplayed", // Times the game has been played
                                "$rating", // Current Game Rating
                                "$gameicon", // The Game Icon
                                                
                    );
      
                    $content.= str_replace($bodytags,$bodyreplacements,$template);
                    
                  if($items_per_row>0)
                    if($number_of_results==$items_per_row){
                      $content.="<div style=\"clear:both;\"></div>";
                      $number_of_results=0;
                    }
            
            }
    
                    if($number_of_results>0){
                      $content.="<div style=\"clear:both;\"></div>";
                    }
    
            
    }
    
            ob_start(); //start output buffer
            include ("./includes/paginate.php");
            $pagenumbers = ob_get_contents(); //$page = output buffer's contents
            ob_end_clean(); //end output buffer
            
            if (empty($searchid))
            $subcategories = display_sub_categories($rewrite,$base_url,$browse_cat_id);
    	$googlead  =  "<br/>".display_ad(5,$base_url);
    
    
                    $bodytags = array(
                    
                                "%pagetitle%", // Title of the Page
                                "%subcategories%", // The Sub-categories
                                "%content%", // The main content for the page
                                "%pagenumbers%", // The page numbers
    			    "%googlead%", // google ad
                   
                    );
      
                   $bodyreplacements = array(
    
                                "$pagetitle", // Title of the Page
                                "$subcategories", // The Sub-categories
                                "$content", // The main content for the page
                                "$pagenumbers", // The page numbers
    			    "$googlead", // googlead
                                                
                    );
      
                    $content = str_replace($bodytags,$bodyreplacements,$maintemplate);
    
    echo $content;
    
    ?>
     
    
    
    PHP:

     
    someone100, Nov 6, 2008 IP