Jump to content

Guidance Limiting Dynamic HTML List Fill


cyprus

Recommended Posts

Thankyou, I have printed the tutorial and have a read tomorow. Looks quite a lot to do, I will cut out color changes unless I can use it to identify product groups in my html table. Also I don't know how its going to slide into  my select queries. Probably all makes sense if I read it - I will. Thanks again
Thought I would post the code in case something was clearer why it did not work. Regards
[code]
<?
session_start();
$_SESSION['Dayte']=date("F j, Y, g:i a");
?>

<?php

$username="root";
// $password="password";
$database="Forders";
mysql_connect(localhost,$username);
mysql_select_db($database) or die( "Unable to select database"); 
//$result = mysql_query($query) or die('Problem with query: ' . $query . '
//    '. mysql_error());



    $limit          = 10;               
    $query_count    = "SELECT count(Ordernumber) FROM Orders";   
    $result_count  = mysql_query($query_count);   
    $totalrows      = mysql_num_rows($result_count); 

    if(empty($page)){
        $page = 1;
    }
       

    $limitvalue = $page * $limit - ($limit); 
    $query  = "SELECT Ordernumber FROM Orders LIMIT $limitvalue, $limit";       
    $result = mysql_query($query) or die("Error: " . mysql_error()); 

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }

    $bgcolor = "#E0E0E0"; // light gray

    echo("<table>");
   
    while($row = mysql_fetch_array($result)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }

    echo("<tr bgcolor=".$bgcolor.">n<td>");
    echo($row["Orderdate"]);
    echo("</td>n<td>");
   
    }

    echo("</table>");

    if($page != 1){ 
        $pageprev = $page--;
       
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); 
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit; 
   
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }


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

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
         
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); 
    }else{
        echo("NEXT".$limit); 
    }
   
    mysql_free_result($result);

?>


</html>
[/code]

MOD EDIT - code tags added. Please use them.
Please accept my aplogies for directing you to that.

Only read the first 6 rows to see there's some crap code in there.

That first query will only return 1 row yet they are trying to use mysql_num_rows() to get total rows! They are doing the right thing by getting COUNT() but ruin it by not picking up it's value.

On to the next bit and $page hasn't been defined (assumes register globals is ON, not uncommon though in older tutorials)

Thanks both. I changed the bits sasa suggested, and that brought the page navigation keys alive apart from the Previous link. Its a shame, thought that would have sorted things out using this code, however will junk it and try and find other code. Again thanks both of you for trying to help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.