Hi, somewhat newbie warning :)

I'm trying to take a paged result set and divide it into two chunks for
displaying on the page. Basically making something that looks like a typical
thumbnail gallery. I'm limiting my result set to 6 records and want to
display it as 2 rows of 3 cells with a record in each cell. I've had no
trouble getting my result set, paging etc. I'm not having much luck
splitting my result into 2 chunks. I've tried nestling 'while' statements
with a number of arguments and either end up with no results or a loop that
seemingly never ends. That lead me to looking at some other apps which
seemed to use a variety of ways to achieve what I want. That lead me to
looking at 'for' and 'foreach' in the php manual. And that lead me to being
more confused than I was before I started ;) Sometimes there's just too many
ways to skin a cat, eh!

Below, I've include a rather lengthy bit of pseudo code that represents
basically where I'm at now. This particular version returns no results,
though I know it's just the nestled while's that are causing this. The
results are there. My research makes me think that I should replace the
nestled while's with 'foreach's. I was kind of hoping that before I spend a
few hours trying to puzzle out how to use the 'foreach's correctly that
somebody would venture an opinion as to whether or not that would be the way
to go.

Thanks in advance for any advice,
Verdon

-- pseudo code --

<?php

$limitPerPage = 6 ;
$initStartLimit = 0;

if (!isset( $startLimit )) {
    $startLimit = $initStartLimit ;
    }

$querylimit = " limit $startLimit,$limitPerPage " ;
$nextStartLimit = $startLimit + $limitPerPage ;
$previousStartLimit = $startLimit - $limitPerPage ;

if ( $sortby != "" ) {
    $sorted = " order by $sortby " ;
    }

$bareQuery = "select * from pieces order by rank";
$queryall = $bareQuery .$sorted .$querylimit;
$resultall = mysql_query ($queryall);
$numberall = mysql_numrows ($resultall);

if ( $numberall == 0) {
    echo "No Records Found !" ;
    } else if ( $numberall > 0) {

    $x = 0;

    echo "<h2>Page of Pieces</h2>";
    
    while ( $x < $numberall ) {
         
        // Retreiving data and putting it in local variables for each row
        $id = mysql_result ($resultall ,$x ,"id");
        $title = mysql_result ($resultall ,$x ,"title");
        $description = mysql_result ($resultall ,$x ,"description");
        $thumb = mysql_result ($resultall ,$x ,"thumb");
        $company = mysql_result ($resultall ,$x ,"company");

        echo "<table cellspacing=\"0\">";
        echo "<tr>";
    
            while ($x >= 0 && $x < 4)
            {    
        
                echo "<td>";
                if ($thumb) {
                    echo "thumbnail with a link";
                    } else {
                    echo "text with a link";
                    }
                echo "<br /><strong>$title</strong>";
                echo "<br />$company";
                echo "<br />$description";
                echo "</td>";
                $x ++;
            }

            echo "</tr>";
            echo "<tr>";

            while ($x > 3 && $x < $numberall)
            {    
        
                echo "<td>";
                if ($thumb) {
                    echo "thumbnail with a link";
                    } else {
                    echo "text with a link";
                    }
                echo "<br /><strong>$title</strong>";
                echo "<br />$company";
                echo "<br />$description";
                echo "</td>";
                $x ++;
            }

            echo "</tr>";
            echo "</table>";
    
            $x ++; 
        } // end while
    echo "</table><br />";
    
    echo "<div class=\"footLinks\">";
    echo "Previous links";
    echo "Next links";
    echo "</div>";

}// end if numberall > 0

?>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to