Results 1 to 2 of 2
  1. #1
    Action Jackson - King of the World
    Join Date
    January 18th, 2005
    Posts
    2,201
    Category menu
    I want to be sure I am using code that is least heavy on the server load. This is my current code. Any suggestions?

    <?
    $user="";
    $host="localhost";
    $password="";
    $database="";

    $connection=mysql_connect($host,$user,$password)
    or die ("couldn't connect to server");
    $db=mysql_select_db($database,$connection);

    $limit=99;
    $query_count="SELECT distinct category FROM underwear";
    $result_count=mysql_query($query_count);
    $totalrows=mysql_num_rows($result_count);
    $page = $_GET['page'];

    if(empty($page))
    {
    $page = 1;
    }
    $limitvalue = ($page * $limit) - $limit;
    $query = "SELECT distinct category FROM underwear order by category LIMIT $limitvalue,$limit";
    $result = mysql_query($query) or die("Error: " . mysql_error());






    ?>

    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>


    <?php
    $prod_columns=1; // Alter this to change number of columns
    $loop_count = 1;
    while($row=mysql_fetch_array($result)){
    ?>

    <td width="<?php print 100/$prod_columns; ?>%" valign="top" align=left>

    <?
    // extract($row);
    $newvar=urlencode($row["category"]);
    ?>



    <a href="http://underweartogo.com/underwear-links.php?interest=<? print $newvar ?>"><? print $row[category]; ?></a>

    </td>

    <?
    if($loop_count == $prod_columns){
    ?>

    <p>

    </tr>
    </table>


    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>

    <?php
    $loop_count = 1;
    }else{
    $loop_count++;
    }
    $count++; // Just for making the while statement work
    }

    ?>

    </tr>
    </table>

    <table width=98% align=center>
    <tr>
    <td>

    <?
    $limit=99;
    if($page != 1){
    $pageprev = $page-1;
    }



    $numofpages = ($totalrows / $limit);
    for($i = 1; $i <= $numofpages; $i++){
    if($i == $page)
    echo($i." ");
    else
    echo("<a href=\"underwearlinks.php?page=$i\">$i</a> "); //removed $ in front of page
    }

    if (floor($totalrows / $limit) != 0) {
    if($i == $page)
    echo($i." ");
    else
    echo("<a href=\"underwearlinks.php?page=$i\">$i</a> ");
    }

    if(($totalrows - ($limit * $page)) > 0){
    $pagenext = $page+ 1;

    }else

    mysql_free_result($result);
    ?>

    </td>
    </tr>
    </table>

  2. #2
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    I would do "select count(distinct category) as totalrows from underwear" in your first query and extract that value rather than use mysql_num_rows(). No point in selecting all of that data when all you need is the row count. It'll just add to your overhead.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  3. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: February 25th, 2009, 02:51 PM
  2. Code to create a Nav menu from a category list
    By Sharan in forum Programming / Datafeeds / Tools
    Replies: 6
    Last Post: July 25th, 2008, 09:29 PM
  3. Menu
    By bsnrjones in forum WebMerge (Fourthworld.com)
    Replies: 4
    Last Post: July 23rd, 2003, 11:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •