We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,466 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Pagination problem with a form

I'm getting stuck with this code. I'm not getting data in second page after form submit.

<?php
session_start();
$user = $_GET['Type'];
include "mysqlConnect.php";
//check for a page number. If not, set it to page 1
if (!(isset($_GET['pagenum']))){
    $pagenum = 1;
}else{
    $pagenum = $_GET['pagenum'];
}
//query for record count to setup pagination
$data = mysql_query("SELECT * FROM tblPhotos WHERE  Type='$user'  ");
$rows = mysql_num_rows($data);
//number of photos per page
$page_rows = 16;
//get the last page number
$last = ceil($rows/$page_rows);
//make sure the page number isn't below one, or more than last page num
if ($pagenum < 1){
    $pagenum = 1;
}elseif ($pagenum > $last){
    $pagenum = $last;
}
//Set the range to display in query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//get all of the photos
$dynamicList = "";
$sql = mysql_query("SELECT * FROM tblPhotos WHERE  Type='$user' $max  ");
//check for photos
$photoCount = mysql_num_rows($sql);
if ($photoCount > 0){
    while($row = mysql_fetch_array($sql)){
            $photoID = $row["PhotoID"];
            $photoName = $row["photoName"];
            $category = $row["category"];
            $dynamicList .= '
                            <div class="thumb">
                                <a href="photo.php?id=' . $photoID . '"><img class="clip" src="galleryPhotos/' . $photoID . '.jpg" alt="' . $photoName . '" width="175" border="0" /></a>
                            </div>
                            ';
    }
}else{
    $dynamicList = "There are no photos at this time!";
}

mysql_close();
?>

<head>
</head>
<body>
<form action= "gallery.php" method='get'>
        <select name="Type">
                <option value="winter">winter</option>
                <option value="summer">sumer</option>

        </select>
        <input type='submit' value = 'filter'>
</form>
    <?php
        echo '<p style="text-align:center; font-weight:bold;">Page ' . $pagenum . ' of ' . $last . '</p>';
          if ($pagenum == 1){
            echo '<div class="pagination" align="center"><ul>';
        }else{
            echo '<div class="pagination" align="center"><ul><li><a href="' . $_SERVER['PHP_SELF']  . '?pagenum=1">« first</a></li>';
            $previous = $pagenum-1;
        }
        //check if number of pages is higher than 1
        if($last != 1){
            //Loop from 1 to last page to create page number links
            for($i = 1; $i <= $last; $i++){
                echo '<li><a href="' . $_SERVER['PHP_SELF'] .'?pagenum=' . $i . '">' . $i . '</a></li>';
            }
        }
        if ($pagenum == $last){
            echo '</div>';
        }else{
            $next = $pagenum+1;
            echo '<li><a href="' . $_SERVER['PHP_SELF'] . '?pagenum=' . $last . '">last »</a></li></ul></div>';
        }
    ?>
     <div id="dataGrid">
        <?php echo $dynamicList; ?>
    </div>
</body>
</html>
3
Contributors
4
Replies
3 Days
Discussion Span
3 Months Ago
Last Updated
6
Views
staffmbm
Newbie Poster
2 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

@staffmbm

I'm getting stuck with this code. I'm not getting data in second page after form submit.

Rather than saying I'm not getting data in second page after form submit.

Can you be more specfic?

These are simple questions you can post regarding how your page is not getting data.

I mean when you run the code what error appears?

Which line does the error occur?

Is your code connected to the database?

LastMitch
Industrious Poster
4,212 posts since Mar 2012
Reputation Points: 134
Solved Threads: 336
Skill Endorsements: 45

Pagination has been done to death on this foru, please search this forum. Also, you say there's a problem - which form are you talking about - the one in the code or another one?
If you could rephrase the question. Also, there's a lot of html / php mixing here. You may find that separating them (keeping php-derived output in variables and outputting them in the relevant places) may help. CHunking up your long procedural code into functions may also help you organize the code, so error trapping is easier.

diafol
Keep Smiling
Moderator
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57

Yes it connected to the database.
In this optional form on the code I'm trying to save value="winter" in session for keep form variable, but seems $users lost then I go to next page after form submit. I'm getting warining on line 13:mysql_num_rows(): supplied argument is not a valid MySQL result resource. Maybe I need add something to URL of second page ? Or it's something wrong with session

staffmbm
Newbie Poster
2 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

In this optional form on the code I'm trying to save value="winter" in session for keep form variable, but seems $users lost then I go to next page after form submit. I'm getting warining on line 13:mysql_num_rows(): supplied argument is not a valid MySQL result resource. Maybe I need add something to URL of second page ? Or it's something wrong with session

$rows = mysql_num_rows($data);

It means there' something wrong with $data another words you are not connected to the database.

LastMitch
Industrious Poster
4,212 posts since Mar 2012
Reputation Points: 134
Solved Threads: 336
Skill Endorsements: 45

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0826 seconds using 2.75MB