PaSha Posted June 27, 2008 Share Posted June 27, 2008 heloo people... hope someone can help me with this little problem, becouse i trying it for days and can't get throw?!?! so here is the problem... i have a search page and the result is this page where the problem is ... i have put the paging code into the result page, where it should show 20 rows per page... and it works good BUT here what happens... the first page shows perfect but when i click NEXT page then i get everything messt-up, becouse then it shows me everything from the databse not only the search stuff... !!! i think the problem is with the memory... it doesn't remember which rows to display after i click NEXT and it shows me ALL rows from the table! i should put the results into an array or something like that but don't know how???? so if someone can help me... please... <?php include '../library/session_proof.php'; include '../library/config.php'; include '../library/opendb.php'; $pronum = $_POST['produktnumer']; $typg_numer = $_POST['typg_numer']; $typk_numer = $_POST['typk_numer']; $typgrund = $_POST['typgrund']; $typkran = $_POST['typkran']; $aufnum = $_POST['auftragsnumer']; $user = $_POST['user']; $kluster = $_POST['clu_id']; $datum = $_POST['datum']; $tip = $_POST['typ_num']; $monter = $_POST['mont']; #var_dump($tip);exit; $flag ="OK"; $msg = ""; $rowsPerPage = 20; $pageNum = 1; if ( isset($_GET['page'])) { $pageNum = $_GET['page']; } $offset = ( $pageNum - 1 ) * $rowsPerPage; $sql = "SELECT input_table.id, user_table.username, cluster_table.name, input_table.created_at, input_table.produkt_numer, input_table.typg_numer, input_table.typk_numer, input_table.typgrund, input_table.typkran, input_table.auftrags_numer, input_table.typ_numer, input_table.mont1, input_table.mont2 FROM input_table,user_table,cluster_table WHERE user_table.id = input_table.user_id AND cluster_table.id = input_table.cluster "; if ( $pronum != NULL ) { $sql .= "AND produkt_numer = '$pronum' "; } if ( $typg_numer != NULL && $typg_numer != '0') { $sql .= "AND typg_numer = '$typg_numer' "; } if ( $typk_numer != NULL && $typk_numer != '0' ) { $sql .= "AND typk_numer = '$typk_numer'"; } if ( $typgrund != NULL ) { $sql .= "AND typgrund = '$typgrund'"; } if ( $typkran != NULL ) { $sql .= "AND typkran = '$typkran'"; } if ( $aufnum != NULL ) { $sql .= "AND auftrags_numer = '$aufnum'"; } if ( $user != NULL ) { $sql .= "AND user_id = '$user'"; } if ( $kluster != NULL && $kluster != 0) { $sql .= "AND cluster = '$kluster'"; } if ( $datum != NULL ) { $sql .= "AND date(input_table.created_at) = '$datum'"; } if ( $tip != NULL && $tip != '0' ) { $sql .= "AND typ_numer = '$tip'"; } if ( $monter != NULL && $monter != 0 ) { $sql .= "AND (mont1 = '$monter' OR mont2 = '$monter')"; } $paging = " LIMIT $offset, $rowsPerPage"; #var_dump($sql);exit; $result = mysql_query($sql.$paging) or die ("Napaka pri branju iz baze! ".mysql_error()); #var_dump($num_rows);exit; #var_dump($sql);exit; //vse prazno /*if(empty($datum) && empty($pronum) && empty($typg_numer) && empty($typk_numer) && empty($typgrund) && empty($typkran)&& empty($aufnum) && empty($user) && empty($kluster) && empty($tip)) { echo "<center>Niste podali iskalnega niza!</center><br>"; echo "<center><input type='button' value='Vrni se' onClick='history.go(-1)'></center><br>"; exit; } else {*/ ?> <div class="table_cluster"> <table border="1" class="table_show_cluster"> <tr class="cluster_naslov"> <td><b>Uporabnik</b></td><td><b>Monterji</b></td><td><b>Narejeno</b></td><td><b>Kluster</b></td><td><b>St.produkta</b></td><td><b>Tip</b></td><td><b>St.naloga</b></td><td><b>Grundgestell</b></td><td><b>Kransaule</b></td> </tr> <?php while( $row = mysql_fetch_array($result) ) { echo "<tr align='center'><td>{$row['username']}</td><td>{$row['mont1']}/{$row['mont2']}</td><td>{$row['created_at']}</td><td>{$row['name']}</td><td>{$row['produkt_numer']}</td><td>{$row['typ_numer']}</td><td>{$row['auftrags_numer']}</td><td>{$row['typg_numer']}-{$row['typgrund']}</td><td>{$row['typk_numer']}-{$row['typkran']}</td></tr>"; } echo '</table></div></div>'; echo '<div class="stevec">'; $result = mysql_query($sql) or die ("Napaka pri branju iz baze! ".mysql_error()); $numrows = mysql_num_rows($result); $maxPage = ceil($numrows/$rowsPerPage); $self = $_SERVER['PHP_SELF']; // creating 'previous' and 'next' link // plus 'first page' and 'last page' link // print 'previous' link only if we're not // on page one if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[-]</a> "; $first = " <a href=\"$self?page=1\">[<<]</a> "; } else { $prev = ' [-] '; // we're on page one, don't enable 'previous' link $first = ' [<<] '; // nor 'first page' link } // print 'next' link only if we're not // on the last page if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[+]</a> "; $last = " <a href=\"$self?page=$maxPage\">[>>]</a> "; } else { $next = ' [+] '; // we're on the last page, don't enable 'next' link $last = ' [>>] '; // nor 'last page' link } // print the page navigation link echo '<center><br><font size=1>'.$first . $prev . " Stran <strong>$pageNum</strong> od <strong>$maxPage</strong> strani " . $next . $last.'</font></center></div>'; include '../library/closedb.php'; ?> Link to comment https://forums.phpfreaks.com/topic/112170-paging-first-page-ok-but-if-i-click-next-then-i-get-problems/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.