SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    Thanks for all the great advice.
    I have a new problem now, I am trying to add a next and previous to my site.
    I can display the first 15 results but when you click on the next button it doesn't display any result.
    Here is the code I have.
    Please help, this is the last thing I have to do, and then I'm done.

    <?


    /*=========================================*/
    /*==Variables used through out the script==*/
    /*=========================================*/
    $server = "localhost"; // Server Name
    $userid = "********"; // Username
    $pass = "********"; // Password
    $database = "***************"; // Database Name
    $dbtable = "******"; // Table Name
    $recordLimit= 15; // Limit per page

    /*==============================================*/
    /*==Font control for the Next/Prev Naviagation==*/
    /*==============================================*/
    $prevStatus = "Show Previous $recordLimit Results";
    $nextStatus = "Show Next $recordLimit Results";
    $prevLink = "< Previous|";
    $nextLink = "|Next >";
    $fontfamily = "tahoma, helvetica";
    $fontsize = "13px";
    $fontcolor = "#000000";
    $inactivecolor = "#666666"; // Color for when there is no link
    $fontweight = "700";
    $textdecoration = "none";

    /*==========================================*/
    /*==Window Status of individual page links==*/
    /*==========================================*/
    function pageStatus($i){
    echo " Click to View Page $i";
    }

    /*========================================*/
    /*==Make server and database connections==*/
    /*========================================*/
    $con = mysql_connect("$server","$userid","$pass")
    or die ("Connection Error to Server");
    $db = mysql_select_db("$database",$con)
    or die("Connection Error to Database");

    /*==================================================*/
    /*==If thisOffset not set, set to zero==============*/
    /*==================================================*/
    if (!isset($thisOffset) || $thisOffset < 0) $thisOffset=0;
    if ($action==search) $thisOffset = $thisOffset - 1;

    /*==================================================*/
    /*==This is to count the line index of the results==*/
    /*=============if not set, set to zero==============*/
    /*==================================================*/
    if (!isset($lineIndex) || $lineIndex < 0) $lineIndex=0;
    if ($action==search) $lineIndex = $lineIndex - 1;

    /*========================================*/
    /*==Set Base SQL Statement for the query==*/
    /*========================================*/
    $sql=("select * from $dbtable WHERE members < '$members' AND software >= '$software' order by rating asc");
    //$sql.=" WHERE category = ''";

    /*======================================*/
    /*==Query for the total number of rows==*/
    /*======================================*/
    $getTotalRows = mysql_query($sql, $con);
    $totalRowsNum = mysql_num_rows($getTotalRows);

    /*==========================================*/
    /*==Append the limit and offset to the sql==*/
    /*==========================================*/
    $sql.="$query Limit $thisOffset,$recordLimit";

    /*===================================================*/
    /*==Query and fetch array with the limit and offset==*/
    /*===================================================*/
    $query = mysql_query($sql, $con);
    while ($result=mysql_fetch_array($query)){

    /*=================================*/
    /*==Increment the line index by 1==*/
    /*=================================*/
    $lineIndex++;

    /*============================================*/
    /*====== Your results layout goes here =======*/
    /*============================================*/

    //**Example:
    //$category=$result['CATEGORY'];
    //$title=$result['TITLE'];
    //echo "$lineIndex. - $category - $title<br>";
    $id=$result ['id'];
    $name=$result ["name"];
    $url=$result ["url"];
    $members=$result ["members"];
    $software=$result ["software"];
    $description=$result ["description"];
    $rating=$result ["rating"];


    print ($result % 2) ? "<tr bgcolor=\"#FFFFFF\">" : "<tr bgcolor=\"#d3d3d3\">";
    echo "<td align=middle><A HREF=\"$url\" target=\"_blank\"><B>$name</B></A></td><td align=middle>$members</td>";
    print "<td align=middle>$software</td>";
    print "<td align=middle>$description</td>";
    print "<td align=middle>$rating</td>";
    }

    /*===================================================================*/
    /*==If the number of returned is less than the limit, show nothing===*/
    /*===================================================================*/
    if ($totalRowsNum <= $recordLimit) {
    // less than recordLimit returned.
    } else {

    /*==============================================*/
    /*==If the current offset is not equal to zero==*/
    /*==Show the link. Else (if>0) show just text===*/
    /*==============================================*/
    if ($thisOffset!=0) { $prevOffset = intval($thisOffset-$recordLimit);
    echo "<a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor; font-weight:$fontweight;"
    ." text-decoration:$textdecoration;' onmouseover=\"window.status='$prevStatus'; return true\""
    ." onmouseout=\"window.status=''\" href=\"$PHP_SELF?thisOffset=$prevOffset&lineIndex=$prevOffset\">"
    ."$prevLink</a>&nbsp;";
    }
    else { echo "<span style='font-family:$fontfamily; font-size:$fontsize; color:$inactivecolor;"
    ." font-weight:$fontweight; text-decoration:$textdecoration;'>$prevLink</span>&nbsp;";
    }

    /*================================================================*/
    /*==Divide total rows by record limit to get the number of pages==*/
    /*================================================================*/
    $totalPages = intval($totalRowsNum/$recordLimit);

    /*===========================================================*/
    /*==If remainder is left from division increment totalPages==*/
    /*===========================================================*/
    if ($totalRowsNum%$recordLimit) $totalPages++;

    /*===========================================================*/
    /*==Using a for() loop, Display links for each page. 1 2 3==*/
    /*===========================================================*/
    for ($i=1;$i<=$totalPages;$i++) {

    /*==================================================================*/
    /*==If the page being viewed is the current page, disable the link==*/
    /*==================================================================*/
    if ((intval($thisOffset/$recordLimit)) == (intval($i-1))) {

    echo "&nbsp;<span style='font-family:$fontfamily; font-size:$fontsize; color:$inactivecolor;"
    ." font-weight:$fontweight; text-decoration:$textdecoration;'>$i</span>&nbsp;";

    } else {
    /*=======================================================*/
    /*==If not current page, set nextOffset and display link==*/
    /*=======================================================*/
    $nextOffset= intval($recordLimit*($i-1));

    echo "&nbsp;<a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor;"
    ." font-weight:$fontweight; text-decoration:$textdecoration;' onmouseover=\"window.status='";
    pageStatus($i);
    echo "'; return true\" onmouseout=\"window.status=''\""
    ." href=\"$PHP_SELF?thisOffset=$nextOffset&lineIndex=$nextOffset\">$i</a>&nbsp;";
    }
    }

    /*==========================================================================*/
    /*==If the page is not the last page, set the nextOffset and show the link==*/
    /*==============If the page is the last page disable the link===============*/
    /*==========================================================================*/
    if (!(intval(((intval($thisOffset/$recordLimit))+1))==$totalPages) && $totalPages!=1) {
    $nextOffset = intval($thisOffset+$recordLimit);

    echo "&nbsp;<a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor; font-weight:$fontweight;"
    ." text-decoration:$textdecoration;' onmouseover=\"window.status='$nextStatus'; return true\""
    ." onmouseout=\"window.status=''\" href=\"$PHP_SELF?thisOffset=$nextOffset&lineIndex=$nextOffset\">$nextLink</a><p>\n";
    }
    else echo "&nbsp;"
    ."<span style='font-family:$fontfamily; font-size:$fontsize; color:$inactivecolor;"
    ." font-weight:$fontweight; text-decoration:$textdecoration;'>$nextLink</span><p>";
    }

    mysql_close($con);
    //End
    ?>


    I really appreciate all the help you have all been.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to pass your search criteria along to the remaining pages in your next link. I will assume there is a variable like category by the way it looks that is passed to this page for the query, you must pas those vars along in the link that makes the next button.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to sound so stupid but could you explain how?

    Thanks

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I thin kthe two you will need are $members and $software s ochange thsi line

    Code:
    echo " <a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor; font-weight:$fontweight;" 
    ." text-decoration:$textdecoration;' onmouseover=\"window.status='$nextStatus'; return true\"" 
    ." onmouseout=\"window.status=''\" href=\"$PHP_SELF?thisOffset=$nextOffset&lineIndex=$nextOffset\">$nextLink</a><p>\n";
    to

    Code:
    echo " <a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor; font-weight:$fontweight;" 
    ." text-decoration:$textdecoration;' onmouseover=\"window.status='$nextStatus'; return true\"" 
    ." onmouseout=\"window.status=''\" href=\"$PHP_SELF?thisOffset=$nextOffset&lineIndex=$nextOffset&members=$members&software=$software\">$nextLink</a><p>\n";
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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