Help With Optimizing This Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help With Optimizing This Script

    Here is a code which uses a lot of resources specially wen say more users are online m not getting how to go abt optimizing it pls help thnx the code goes like this :-

    Code:
    <? include(&#39;header.php&#39;); ?>
    
    <h3>Surf Ads - Visit Websites</h3>
    
    
    
    
    <?
    require(&#39;config.php&#39;);
    $tabla = mysql_query("SELECT id FROM tb_ads_categories ORDER BY id ASC"); // selecciono todos los registros de la tabla usuarios, ordenado por nombre
    mysql_close($con);
    while ($registro = mysql_fetch_array($tabla)) { // comienza un bucle que leera todos los registros y ejecutara las ordenes que siguen
    
    
    ?>
    
    <?
        $indice = $registro["id"];
    require(&#39;config.php&#39;);
    $sql = "SELECT * FROM tb_ads_categories WHERE id=&#39;$indice&#39;";
    $result = mysql_query($sql);        
    $row = mysql_fetch_array($result);
    mysql_close($con);
    ?>
    <div id="tables">
    <table width="80%" align="center">
    
    <tr>
    <th class="top" width="61%">
    [b] <? echo $row["catname"] ?>[/b]
    </th>
    <th class="top" width="13%">
    <div align="center">
    [b]Members[/b]</div>
    </th>
    <th class="top" width="13%">
    <div align="center">
    [b]Outside[/b]</div>
    </th>
    <th class="top" width="13%">
    <div align="center">
    [b]Total[/b]</div>
    </th>
    </tr>
    
    <?php
    
    
    
    /* Pedimos todos los temas iniciales (identificador==0)
    * y los ordenamos por ult_respuesta */
    
    if(isset($_COOKIE["usNick"]) && isset($_COOKIE["usPass"]))
    {
    
    
    $lolz=$_COOKIE["usNick"];
    
    require(&#39;config.php&#39;);
    $sqlr = "SELECT * FROM tb_users WHERE username=&#39;$lolz&#39;";
    $resultr = mysql_query($sqlr);        
    $myrowr = mysql_fetch_array($resultr);
    mysql_close($con);
    $tipr=$myrowr["account"];
    
    
    switch($tipr) {
        case("premium"):
    require(&#39;config.php&#39;);
    $sql = "SELECT * ";
    $sql.= "FROM tb_ads WHERE tipo=&#39;ads&#39; and category=&#39;$indice&#39; ORDER BY fechainicia DESC";
    $rs = mysql_query($sql, $con);
    mysql_close($con);
    if(mysql_num_rows($rs)>0)
    {
        // Leemos el contenido de la plantilla de temas
        $template = implode("", file("titulosp.php"));
    
        while($row = mysql_fetch_assoc($rs))
        {
    
    
    $row["last"]=uc($_COOKIE["usNick"]);
    
    
    $row["total"]=$row["outside"] + $row["members"];
    
    $bold=$row["bold"];
    if ($bold=="1")
    {
    $row["bold"]="[b]";
    $row["boldc"]="[/b]";
    }
    
    
    $highlight=$row["highlight"];
    if ($highlight=="1")
    {
    $row["highlight"]="#cccccc";
    $row["highlight"]="#cccccc";
    }
    
    $ji=$row["members"];
    $jo=$row["plan"];
    if ($ji >= $jo)
    {
    
    
    
    
    $row["description"]="";
    $row["members"]="";
    $row["outside"]="";
    $row["total"]="";
    $row["id"]="";
    }
    
            mostrarTemplate($template, $row);
    
        }
    }
    
          break;
    
        default:
    require(&#39;config.php&#39;);
    $sql = "SELECT * ";
    $sql.= "FROM tb_ads WHERE tipo=&#39;ads&#39; and category=&#39;$indice&#39; ORDER BY fechainicia DESC";
    $rs = mysql_query($sql, $con);
    mysql_close($con);
    if(mysql_num_rows($rs)>0)
    {
        // Leemos el contenido de la plantilla de temas
        $template = implode("", file("titulos.php"));
    
        while($row = mysql_fetch_assoc($rs))
        {
    
    
    $row["last"]=uc($_COOKIE["usNick"]);
    
    
    $row["total"]=$row["outside"] + $row["members"];
    
    $bold=$row["bold"];
    if ($bold=="1")
    {
    $row["bold"]="[b]";
    $row["boldc"]="[/b]";
    }
    
    
    $highlight=$row["highlight"];
    if ($highlight=="1")
    {
    $row["highlight"]="#cccccc";
    $row["highlight"]="#cccccc";
    }
    
    $ji=$row["members"];
    $jo=$row["plan"];
    if ($ji >= $jo)
    {
    
    
    
    
    $row["description"]="";
    $row["members"]="";
    $row["outside"]="";
    $row["total"]="";
    $row["id"]="";
    }
    
            mostrarTemplate($template, $row);
    
        }
    }
    
    }
    
    }else{
    
    require(&#39;config.php&#39;);
    //require(&#39;funciones.php&#39;);
    
    $sqlr = "SELECT * ";
    $sqlr.= "FROM tb_ads WHERE tipo=&#39;ads&#39; and category=&#39;$indice&#39; ORDER BY fechainicia DESC";
    $rsr = mysql_query($sqlr, $con);
    mysql_close($con);
    if(mysql_num_rows($rsr)>0)
    {
        // Leemos el contenido de la plantilla de temas
        $templater = implode("", file("titulos1.php"));
    
        while($rowr = mysql_fetch_assoc($rsr))
        {
    
    
    $rowr["total"]=$rowr["outside"] + $rowr["members"];
    
    
    $bold=$rowr["bold"];
    if ($bold=="1")
    {
    $rowr["bold"]="[b]";
    $rowr["boldc"]="[/b]";
    }
    
    $highlight=$rowr["highlight"];
    if ($highlight=="1")
    {
    $rowr["highlight"]="#cccccc";
    $rowr["highlight"]="#cccccc";
    }
    
    
    $ji=$rowr["members"];
    $jo=$rowr["plan"];
    if ($ji >= $jo)
    {
    $rowr["description"]="";
    $rowr["members"]="";
    $rowr["outside"]="";
    $rowr["total"]="";
    $rowr["id"]="";
    }
    
    
            mostrarTemplate($templater, $rowr);
    
        }
    }
    
    
    
    }
    
    
    
    
    ?>
    
    </table>
    
    </div>
    
    
    
    
    
    
    
    
    
    
    
    
    <?
    
    } // fin del bucle de ordenes
    
    
    
    ?>
    
    
    
    
    
    
    
    
    
    
    
            
    <? include(&#39;footer.php&#39;); ?>

    <span style="font-size:12pt;line-height:100%"><span style="color:#FF0000">ViSiT Ma SiTe Nd PoSt Ua CoMmEnTs On It In Ma PoSt</span></span>

    #2
    Go through every page and remove all the connects, just have one connect and one close on each page, this helps loads.

    Comment


      #3
      ok i thought closing connection after each querry makes load less on cpu ...i also want the sql querries optimized it wud be great if someone gives an optimized coding example for this so i can test it ..i tryed wht i could do nothing really worked much..
      <span style="font-size:12pt;line-height:100%"><span style="color:#FF0000">ViSiT Ma SiTe Nd PoSt Ua CoMmEnTs On It In Ma PoSt</span></span>

      Comment


        #4
        Atleast give some suggestions ...wht can be done it wud be higly appreciable if u put up some points for it so tht the script uses less cpu bandwidth is not issue ..thnx
        <span style="font-size:12pt;line-height:100%"><span style="color:#FF0000">ViSiT Ma SiTe Nd PoSt Ua CoMmEnTs On It In Ma PoSt</span></span>

        Comment

        Working...
        X