Jump to content

Another pagiantion problem


kvnirvana

Recommended Posts

  
<?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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.