You are here: Re: database retrieval problem while formatting « PHP Programming Language « IT news, forums, messages
Re: database retrieval problem while formatting

Posted by Gordon Burditt on 10/22/02 11:58

>The code posted below retrieves all of the rows from a database table.
>It paginates them by limiting to 20 results per page. It is supposed
>to print 5 rows of results with 4 results per row. Everything works
>fine, except the first row returned from the database is never printed.
> It doesn't matter how the results are ordered or how many rows are in
>the db, the first row that is supposed to be printed is not printed.
>
>Does anyone have any thoughts? I have been going nuts over this for
>the past day.
>
>Any feedback would be great. Thanks!
>
><?php
>
> $limit = 20;
> $query_count = "SELECT * FROM lounge_products";
> $result_count = mysql_query($query_count);
> $totalrows = mysql_num_rows($result_count);
>
> $PHP_SELF = $_SERVER['PHP_SELF'];
>
> if(!isset($_GET['page'])){ // Checks if the $page variable is empty
>(not set)
> $page = 1; // If it is empty, we're on page 1
> } else{
> $page = $_GET['page'];
> }
>
> $limitvalue = $page * $limit - ($limit );
> // Ex: (page2 * 5(items per page) = 10) - 5 = 5 <- data starts at 5
>
> $query = "SELECT * FROM lounge_products ORDER BY artist_name DESC
>LIMIT $limitvalue, $limit";
> $result = mysql_query($query) or die("Error: " . mysql_error());
>
> if(mysql_num_rows($result) == 0){
> echo("Nothing to Display!");
> }
> echo("<table>");
>
> while($row = mysql_fetch_array($result)){

***ABOVE YOU FETCH THE FIRST ROW***

> $counter = 0;
> $cells_per_row = 4;
> while($row=mysql_fetch_array($result))
***ABOVE YOU FETCH THE SECOND ROW, WIPING OUT THE ONLY COPY OF THE FIRST ROW***

> {
> $counter++;
> print $counter;
> if(($counter % $cells_per_row) == 1) { echo '<tr>'; }

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация