Jump to content

Archived

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

cyprus

Guidance Limiting Dynamic HTML List Fill

Recommended Posts

I have an HTML table that dynamically fills from a select query. It works well however I have to think about curbing its height, otherwise my page will be a few miles high. Anybody got a suggestion as to avoiding such a disaster? Thanks

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
I cut and pasted all the code from the first example into a page, amended all db references, and it just produced a series of n's at the left hand side, the links to goto the next page were dead? Any ideas why it does not burst into life? Thanks.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
1 st change [code]$totalrows      = mysql_num_rows($result_count);  [/code]to
[code]$totalrows      = mysql_result($result_count,0,0);  [/code]
2nd change[code]$pageprev = $page--; [/code]to[code]$pageprev = $page-1; [/code]

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Anbody following my footsteps, this reference helped me and worked. Hope it helps someone else.

http://www.tonymarston.net/php-mysql/pagination.html

Share this post


Link to post
Share on other sites

×

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.