Jump to content


Photo

Guidance Limiting Dynamic HTML List Fill


  • Please log in to reply
8 replies to this topic

#1 cyprus

cyprus
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 24 September 2006 - 07:53 PM

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 24 September 2006 - 08:16 PM

http://www.phpfreaks...-Pagination.php
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 cyprus

cyprus
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 24 September 2006 - 09:01 PM

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

#4 cyprus

cyprus
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 25 September 2006 - 08:01 PM

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.

#5 cyprus

cyprus
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 25 September 2006 - 08:05 PM

Thought I would post the code in case something was clearer why it did not work. Regards
<?
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>

MOD EDIT - code tags added. Please use them.

#6 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 25 September 2006 - 08:31 PM

1 st change
$totalrows      = mysql_num_rows($result_count); 
to
$totalrows      = mysql_result($result_count,0,0); 
2nd change
$pageprev = $page--;
to
$pageprev = $page-1;


#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 25 September 2006 - 08:36 PM

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)


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 cyprus

cyprus
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 25 September 2006 - 08:51 PM

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.

#9 cyprus

cyprus
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 26 September 2006 - 06:25 AM

Anbody following my footsteps, this reference helped me and worked. Hope it helps someone else.

http://www.tonymarst...pagination.html




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users