Jump to content

Layout View


phphelp!

Recommended Posts

Hello,

 

I need some help modifying some code. I would like to change the layout to show more then currently offered.

As of now I have a layout that shows either 3 or 10 images. I tried to change the numbers, but no luck and I can not seem to be able to change to view more.

Any help would be great!

 

 // image list
$mysqlDataImage = mysql_query( "SELECT * FROM $DB_IMAGE where collectionID=$cat $where ORDER BY $order_by" );
$dataLength = mysql_num_rows( $mysqlDataImage );
$totalImages = $dataLength;

//$cat_scrollview = 3; //FORCE SCROLLER
if($scrollview == "smaller"){ $cat_scrollview = 0; } //User Override

//SWITCH SCROLL LAYOUT BASED ON VIEW : HANDLES COLUMNS, ROWS, PAGES AND SHOW ALL
if (($cat_scrollview == 3)||($scrollview == "bigger")){  
$PAGE_SIZE = 3; //how many pics per page, all set in html
$rowDefault = 1; //row default-changes the most
$colDefault = $totalImages/ 1; //columns default use to breakup columns
//echo "cols=".$colDefault;
//echo "totalimage=".$totalImages;
//See getNumberOfRows()
$totalPages = $totalImages/$PAGE_SIZE;
$cat_scrollview = 3;
$scrollview = "bigger";
}else{
$PAGE_SIZE = 10; //how many pics per page, all set in html
$rowDefault = 2; //row default-changes the most
$colDefault = $totalImages/ 2; //columns default use to breakup columns
//echo "cols=".$colDefault;
//echo "totalimage=".$totalImages;
//See getNumberOfRows()
$totalPages = $totalImages/$PAGE_SIZE;
$cat_scrollview = 0;
$scrollview = "smaller";
}

 

 

I am new to PHP so please be kind (and explain slowly) Thank you!

Link to comment
https://forums.phpfreaks.com/topic/226698-layout-view/
Share on other sites


The $where var is empty ... theres no limit in the SQL and the vars seems ok ...

Unless you post the hole code theres nothing i can do to help at this point ...

 

But if your looking to post X number of images by X number of line you can try this code i made

 

<?php

        $mypage = "media_image.php?"; // Keep the ? at the end or finish it with & if you already have vars
        $nb_per_page = 9;
        $image_folder = "images";
        $col = 3; 

        if ($_GET

 == "") { $num_page = 1; } else { $num_page = $_GET['page']; }
        $offset = ($num_page - 1) * $nb_per_page;
        $nb_images = @current(@mysql_fetch_assoc(@mysql_query("SELECT count(id) FROM $DB_IMAGE")));
        $re_page = $num_page * $nb_per_page;
        $ree_page = $re_page - $nb_per_page;
        $row = 0;

        // Start of the table
        print ('<table border="0" cellpadding="3" cellspacing="3" width="100%" id="table1"><tr>');
        
        // Start the loop
        $select = mysql_query("SELECT * FROM $DB_IMAGE where collectionID=$cat $where ORDER BY $order_by limit $offset, $nb_per_page") or die(mysql_error());
        while ($categ_list = mysql_fetch_array($select)) {

            // Lets show the images
            print ('<td align="center" valign="top"><img width="200" border="0" src="'.$image_folder.'/' . $categ_list[photo] .'"></td>');

            if ($row == $col) {
                echo '</tr><tr>';
                $row = 0;
            }
            $row++;

        }

        // Close the table
        echo "</table>";

        $maxPage = ceil($nb_images / $nb_per_page);

        $self = "$mypage";
        $nav = '';
        for ($page = 1; $page <= $maxPage; $page++) {
            if ($page == $num_page) {
                $nav .= " $page ";
            } else {
                $nav .= " <a href=\"$self&page=$page\">$page</a> ";
            }
        }

        if ($num_page > 1) {
            $page = $num_page - 1;
            $prev = " <a href=\"$self&page=$page\">[Précédant]</a> ";

            $first = " <a href=\"$self&page=1\">[First page]</a> ";
        } else {
            $prev = ' ';
            $first = ' ';
        }

        if ($num_page < $maxPage) {
            $page = $num_page + 1;
            $next = " <a href=\"$self&page=$page\">[Next]</a> ";

            $last = " <a href=\"$self&page=$maxPage\">[Last page]</a> ";
        } else {
            $next = ' ';
            $last = ' ';
        }
        if ($re_page >= "$nb_images") {
            $re_page = "$nb_images";
        }

        // Navigation
        print ("<center><br>($ree_page to $re_page from $nb_images)  Page:<b>$first $prev $nav $next $last</center>");

?>

 

@Maq, It was only 1 line of code ... i use the [ code ] and [ php ] only when theres more then one line

 

 

Link to comment
https://forums.phpfreaks.com/topic/226698-layout-view/#findComment-1169939
Share on other sites

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.