kvnirvana Posted September 29, 2010 Share Posted September 29, 2010 <?php session_start();?> <html> <head> <title>Mit dokument</title> <link rel="stylesheet" type="text/css" href="drop.css"> </head> <body> <script language="javascript"> function reload(form){ var val=form.be.options[form.be.options.selectedIndex].value; var val2=form.omraede.options[form.omraede.options.selectedIndex].value; self.location='bedoembehan.php?be=' + val +'&omraede=' + val2 ; } </script> <?php <form action="<?php echo $_SERVER['PHP_SELF']?>" > <table width='100%' align='center' valign='center'> <tr> <td colspan='2' align='center' style='font-family:verdana;font-size:130%;'><strong>Find </strong><br></br></td> </tr> <th align="left" scope="col"> </table> <?php @$cat=$_GET['be']; @$catt=$_GET['omraede']; @$cattt=$_GET['na']; $quer1=mysql_query("SELECT DISTINCT be FROM behan order by id"); $quer2=mysql_query("SELECT distinct omraede FROM behan WHERE be='$cat' order by id"); // First drop down echo "<table width='50%' style='position:absolute;left:545px;top:70px;width:100%;height:100%'>"; echo "<tr>"; echo "<td style='font-family:verdana;font-size:110%;'></td>"; echo "<select name='be' style='font-size: 18px;' onchange=\"reload(this.form)\"><option value=''>Væl</option>"; while($noticia2 = mysql_fetch_array($quer1)) { if($noticia2['be']==@$cat){ echo "<option selected value='$noticia2[be]'>$noticia2[be]</option>"; }else{ echo "<option value='$noticia2[be]'>$noticia2[be]</option>"; } } echo "</select>"; echo "<td"; echo "<tr>"; // Second drop down echo "<br>"; echo "<br>"; echo "<tr>"; echo "<td style='font-family:verdana;font-size:110%;'></td>"; echo "<select name='omraede' style='font-size: 18px;' onchange=\"reload(this.form)\"><option value=''>Vælg område</option>"; while($noticia = mysql_fetch_array($quer2)) { if($noticia['omraede']==@$catt){ echo "<option value='$noticia[omraede]'>$noticia[omraede]</option>"; }else{ echo "<option value='$noticia[omraede]'>$noticia[omraede]</option>"; } } echo "</select>"; echo "</td>"; echo "</tr>"; echo "</table>"; $records_per_page = 1; $quer3=mysql_query("SELECT * FROM behan WHERE be='$cat' and omraede='$catt' group by na order by na"); $result=mysql_query($quer3); //-count results $numrows=mysql_num_rows($result); $num_pages = ceil($numrows/$records_per_page); //Determine the page to display $current_page = (isset($_SESSION['pg'])) ? (int) $_SESSION['pg'] : 1; if($current_page<1 || $current_page>$num_pages) { $current_page = 1; } //Define the limit start position for the current page of records (for current filter) $limitstart = (($current_page-1)*$records_per_page); $quer4=mysql_query("SELECT * FROM behan WHERE be='$cat' and omraede='$catt' group by na order by na LIMIT $limitstart, $records_per_page"); // Vis resultat echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<TABLE width=100% height=100 border='0' cellpadding='5' cellspacing='10'>"; echo "<tr>"; echo "<td style='font-family:verdana;font-size:110%;'></td>"; echo ""; while($rows = mysql_fetch_array($quer4)) { echo "<TR>"; echo "<TH><p style='font-family:verdana;font-size:100%;text-align:justify;text-decoration:underline;'>Be</p></TH>"; echo "</TR>"; echo "<TR>"; echo "<TD><p style='font-family:verdana;font-size:100%;'>". $rows['be'] ."<br> ". $rows['na'] ."<br> ". $rows['ad'] ."<br> ". $rows['po'] .", ". $rows['by'] ."<br> ". $rows['tl'] ."<br><br>"."<a href='bedoem.php?id={$rows['id']}&na={$rows['na']}&pro={$rows['pro']}&be={$rows['be']}&omraede={$rows['omraede']}&ad={$rows['ad']}&tl={$rows['tl']}&po={$rows['po']}'>Bed </a></p></TD>"; echo "<TABLE width=70% height=100 border='0' cellpadding='5' cellspacing='10'><hr>"; echo "</TR>"; } if($num_pages>1) { $thisroot = $_SERVER['PHP_SELF']; echo "<strong>Sider:</strong> "; //Create link to navigate to last page if($current_page > 1) { echo "<a href=\"{$thisroot}?pg=" . ($current_page-1) . "\"><< Forrige</a> \n"; } //Create individual page links for($page=1; $page<=$num_pages; $page++) { echo ($page!= $current_page) ? "<a href=\"{$thisroot}?pg={$page}\">$page</a>" : $page; echo " "; } //Create link to next page if($current_page < $num_pages) { echo "<a href=\"{$thisroot}?pg=" . ($current_page+1) . "\">Næste >></a>"; } } ///////////////// ?> When clicking on a letter it shows words that start with that letter. If more than 3 words it makes a page link to the next page to see the next 3 words. The problem is that if I want to see the next 3 words, it will off course take me to the next page, page 2. If I then want to see words that begin with another letter, and I click on that letter, and that letter has more than 3 words, it stays on page 2. So if I click on the letter B and then click on the "next" link to see the next 3 results, and then click on the letter A, it shows me words starting with the letter A but with the values from page 2 assuming there are more than 3 results. Quote Link to comment https://forums.phpfreaks.com/topic/214761-another-pagiantion-problem/ Share on other sites More sharing options...
Psycho Posted September 29, 2010 Share Posted September 29, 2010 OK, I'm assuming English is not your primary language because I don't understand your variable names which makes it difficult to understand. It looks like you are storing the current page as a session variable, but are passing other parameters for filtering via GET. Not sure why you woul dneed to store the page number as a session variable. You could pass the page variable as an additional GET parameter. If it is set then override the session value or don't use the session variable at all. Alternatively you could save the last used "letter" to a session variable. Then when the script detects that the new letter is different than the last then it should default to page 1. Quote Link to comment https://forums.phpfreaks.com/topic/214761-another-pagiantion-problem/#findComment-1117323 Share on other sites More sharing options...
kvnirvana Posted September 29, 2010 Author Share Posted September 29, 2010 Ok I see your point, I removed the session variable and changed all $_SESSION to $_GET. But how do I pass the page variable as an additional GET parameter as you suggested? Quote Link to comment https://forums.phpfreaks.com/topic/214761-another-pagiantion-problem/#findComment-1117345 Share on other sites More sharing options...
Psycho Posted September 29, 2010 Share Posted September 29, 2010 Well, unless the user is changing pages you don't need to pass the page variable. If the user is selecting a different letter or other filter criteria you want to go back to page 1. So your code woul dlook something like this $current_page = (isset($_GET['page']))?$_GET['page']:1; The only place you would need to pass the page variable is when the user selects a next or previous page or selects an actual page to navigate to. So, just modify those links as needed. Example echo "<a href=\"thispage.php?page=".($current_page-1)."\">Next Page</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/214761-another-pagiantion-problem/#findComment-1117353 Share on other sites More sharing options...
kvnirvana Posted September 30, 2010 Author Share Posted September 30, 2010 Thank you so much it worked :=) Maybe you can help me with this last page :=) This code is from a page called new.php. The problem is that when I click next to see the next results it shows, of course, page 2. If I then open another page to see some other content, and then click on the link to see new.php again its still on page 2. I think I need to use the SESSION here right? I tried to do it without the SESSION but then nothing works. <?php session_start();?> <html> <head> <title>Mit dokument</title> <link rel="stylesheet" type="text/css" href="drop.css"> </head> <body> <script language="javascript"> function reload(form){ var val=form.be.options[form.be.options.selectedIndex].value; var val2=form.omraede.options[form.omraede.options.selectedIndex].value; self.location='bedmbe.php?be=' + val +'&omraede=' + val2 ; } </script> <div class="content_top"></div> <div class="content_only"> <form action="<?php echo $_SERVER['PHP_SELF']?>" > <table width='100%' align='center' valign='center'> <tr> <td colspan='2' align='center' style='font-family:verdana;font-size:130%;'><strong>Fi</strong><br></br></td> </tr> <th align="left" scope="col"> </table> <?php if (isset($_GET)) { foreach($_GET as $k=>$v) { $_SESSION[$k]=$v; }} @$cat=$_SESSION['be']; @$catt=$_SESSION['omraede']; @$cattt=$_SESSION['na']; $quer1=mysql_query("SELECT DISTINCT be FROM behan order by id"); $quer2=mysql_query("SELECT distinct omraede FROM behan WHERE be='$cat' order by id"); // First drop down echo "<table width='50%' style='position:absolute;left:545px;top:70px;width:100%;height:100%'>"; echo "<tr>"; echo "<td style='font-family:verdana;font-size:110%;'></td>"; echo "<select name='be' style='font-size: 18px;' onchange=\"reload(this.form)\"><option value=''>be</option>"; while($noticia2 = mysql_fetch_array($quer1)) { if($noticia2['be']==@$cat){ echo "<option selected value='$noticia2[be]'>$noticia2[be]</option>"; }else{ echo "<option value='$noticia2[be]'>$noticia2[be]</option>"; } } echo "</select>"; echo "<td"; echo "<tr>"; // Second drop down echo "<br>"; echo "<br>"; echo "<tr>"; echo "<td style='font-family:verdana;font-size:110%;'></td>"; echo "<select name='omraede' style='font-size: 18px;' onchange=\"reload(this.form)\"><option value=''>Vælg område</option>"; while($noticia = mysql_fetch_array($quer2)) { if($noticia['omraede']==@$catt){ echo "<option value='$noticia[omraede]'>$noticia[omraede]</option>"; }else{ echo "<option value='$noticia[omraede]'>$noticia[omraede]</option>"; } } echo "</select>"; echo "</td>"; echo "</tr>"; echo "</table>"; $records_per_page = 1; $quer3=mysql_query("SELECT * FROM behan WHERE be='$cat' and omraede='$catt' group by na order by na"); $numrows=mysql_num_rows($quer3); //-count results $num_pages = ceil($numrows/$records_per_page); //Determine the page to display $current_page = (isset($_SESSION['pg'])) ? (int) $_SESSION['pg'] : 1; if($current_page<1 || $current_page>$num_pages) { $current_page = 1; } //Define the limit start position for the current page of records (for current filter) $limitstart = (($current_page-1)*$records_per_page); $quer4=mysql_query("SELECT * FROM behan WHERE be='$cat' and omraede='$catt' group by na order by na LIMIT $limitstart, $records_per_page"); // Vis resultat echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<TABLE width=100% height=100 border='0' cellpadding='5' cellspacing='10'>"; echo "<tr>"; echo "<td style='font-family:verdana;font-size:110%;'></td>"; echo ""; while($rows = mysql_fetch_array($quer4)) { echo "<TR>"; echo "<TH><p style='font-family:verdana;font-size:100%;text-align:justify;text-decoration:underline;'>Behandler</p></TH>"; echo "</TR>"; echo "<TR>"; echo "<TD><p style='font-family:verdana;font-size:100%;'>". $rows['be'] ."<br> ". $rows['na'] ."<br> ". $rows['ad'] ."<br> ". $rows['po'] .", ". $rows['by'] ."<br> ". $rows['tl'] ."<br><br>"."<a href='bedoem.php?id={$rows['id']}&na={$rows['na']}&pro={$rows['pro']}&be={$rows['be']}&omraede={$rows['omraede']}&ad={$rows['ad']}&tl={$rows['tl']}&po={$rows['po']}'>B </a></p></TD>"; echo "<TABLE width=70% height=100 border='0' cellpadding='5' cellspacing='10'><hr>"; echo "</TR>"; } if($num_pages>1) { $thisroot = $_SERVER['PHP_SELF']; echo "<strong>Sider:</strong> "; //Create link to navigate to last page if($current_page > 1) { echo "<a href=\"{$thisroot}?pg=" . ($current_page-1) . "\"><< Forrige</a> \n"; } //Create individual page links for($page=1; $page<=$num_pages; $page++) { echo ($page!= $current_page) ? "<a href=\"{$thisroot}?pg={$page}\">$page</a>" : $page; echo " "; } //Create link to next page if($current_page < $num_pages) { echo "<a href=\"{$thisroot}?pg=" . ($current_page+1) ."\">Næste >></a>"; } } ///////////////// echo "</table>"; echo "<table>"; echo "<tr></td> <td style='position:absolute;right:18px;top:36px' 'tdimage' BACKGROUND='forside1.jpg' width='290' height='600'></td></tr>"; echo "</table>"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/214761-another-pagiantion-problem/#findComment-1117638 Share on other sites More sharing options...
Psycho Posted September 30, 2010 Share Posted September 30, 2010 I thought you were changing the current page assignment to use a GET variable instead of a SESSION variable. But, I still see this in your code $current_page = (isset($_SESSION['pg'])) ? (int) $_SESSION['pg'] : 1; What is happening is that when you open the other page, that page is starting at page 1 and resetting the session variable to page 1. So, when you go back to the original window and hit the next page link it is going to page 2 (which is the next page from page 1 as stored in the session variable). I stated previously that I didn't know why you would be using SESSION to store the current page number, but I assumed you had a reason for doing so. You need to think about how stored data should be used and the appropriate method for storing it. If a user is expected to open multiple browser windows with different data from the same site you should not be using SESSION variables to store any parameters for that data. I suppose you could use SESSION variables if you wanted to build it so that each windows/gid had it's own namespace in the session data. But, that would seem to just overcomplicate this more than it needs to be. Quote Link to comment https://forums.phpfreaks.com/topic/214761-another-pagiantion-problem/#findComment-1117647 Share on other sites More sharing options...
kvnirvana Posted September 30, 2010 Author Share Posted September 30, 2010 Ok, now it works, once again thank for helping :=) Quote Link to comment https://forums.phpfreaks.com/topic/214761-another-pagiantion-problem/#findComment-1117671 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.