FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » pagination driving me insane
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
pagination driving me insane [message #174607] Tue, 21 June 2011 21:22 Go to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
Hi All,

I have a page which displays accounts. On the page there are three
search options:

1. sort by newest members first;
2. search by country;
3. search by name;

There is a limit of 10 accounts per page. If the query returns more
than 10 records I have to browse to the next page.
So I need to save the search options in the url when I go to the next
page. I tried the following code but it doesn't work properly:

// check if any of the three buttons were clicked
if(isset($_POST['listByq']) {

// did I click the search by country button
if ($_POST['listByq'] == "by_country") {

$value = $_POST['country']; //put the country name in the
variable for the URL
$country = $_POST['country'];
$queryString = "WHERE country='$country' AND email_activated='1'";
$choice = $_POST['listByq']; } //put by_country in the variable
for the URL

// did I click on the searh by firstname
else if ($_POST['listByq'] == "by_firstname") {

$value = $_POST['fname'];
$firstname = $_POST['fname'];
$firstname = mysql_real_escape_string($firstname);
$queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
LIKE '%$firstname%' AND email_activated='1'";
$choice = $_POST['listByq'];

// or did I click the newest members first sort order
} else if ($_POST['listByq'] == "newest_members") {

$value = "";
$queryString = "WHERE email_activated='1' ORDER BY id DESC";
$choice = $_POST['listByq'];
}
}

// now get the values form the URL
if (isset($_GET['choice'])) {
$choice = $_GET['choice'];
$value = $_GET['value'];
}

// if there was anything in $choice
if ($choice <> "") {
if($choice = "by_country") {
$country = $value;
$queryString = "WHERE country='$country' AND
email_activated='1'";
else if ($choice= "by_firstname") {
$firstname = $value;
$queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
LIKE '%$firstname%' AND email_activated='1'";
$queryMsg = "Showing Members with the name you searched for"; }
else if ($choice= "newest_members") {
$queryString = "WHERE email_activated='1' ORDER BY id DESC";
}

}

The pagination looks like this:
$centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' .
$add1 . '&choice=' . $choice . '&value=' . $value . '">' . $add1 . '</
a> &nbsp;';

I know there must be a solution for this which works but I have looked
at it from all sides but I don't get it.
Does anyone know how to get this working?



Marco
Re: pagination driving me insane [message #174609 is a reply to message #174607] Wed, 22 June 2011 02:18 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/21/2011 5:22 PM, Co wrote:
> Hi All,
>
> I have a page which displays accounts. On the page there are three
> search options:
>
> 1. sort by newest members first;
> 2. search by country;
> 3. search by name;
>
> There is a limit of 10 accounts per page. If the query returns more
> than 10 records I have to browse to the next page.
> So I need to save the search options in the url when I go to the next
> page. I tried the following code but it doesn't work properly:
>
> // check if any of the three buttons were clicked
> if(isset($_POST['listByq']) {
>
> // did I click the search by country button
> if ($_POST['listByq'] == "by_country") {
>
> $value = $_POST['country']; //put the country name in the
> variable for the URL
> $country = $_POST['country'];
> $queryString = "WHERE country='$country' AND email_activated='1'";
> $choice = $_POST['listByq']; } //put by_country in the variable
> for the URL
>
> // did I click on the searh by firstname
> else if ($_POST['listByq'] == "by_firstname") {
>
> $value = $_POST['fname'];
> $firstname = $_POST['fname'];
> $firstname = mysql_real_escape_string($firstname);
> $queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
> LIKE '%$firstname%' AND email_activated='1'";
> $choice = $_POST['listByq'];
>
> // or did I click the newest members first sort order
> } else if ($_POST['listByq'] == "newest_members") {
>
> $value = "";
> $queryString = "WHERE email_activated='1' ORDER BY id DESC";
> $choice = $_POST['listByq'];
> }
> }
>
> // now get the values form the URL
> if (isset($_GET['choice'])) {
> $choice = $_GET['choice'];
> $value = $_GET['value'];
> }
>
> // if there was anything in $choice
> if ($choice<> "") {
> if($choice = "by_country") {
> $country = $value;
> $queryString = "WHERE country='$country' AND
> email_activated='1'";
> else if ($choice= "by_firstname") {
> $firstname = $value;
> $queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
> LIKE '%$firstname%' AND email_activated='1'";
> $queryMsg = "Showing Members with the name you searched for"; }
> else if ($choice= "newest_members") {
> $queryString = "WHERE email_activated='1' ORDER BY id DESC";
> }
>
> }
>
> The pagination looks like this:
> $centerPages .= '&nbsp;<a href="' . $_SERVER['PHP_SELF'] . '?pn=' .
> $add1 . '&choice=' . $choice . '&value=' . $value . '">' . $add1 .'</
> a> &nbsp;';
>
> I know there must be a solution for this which works but I have looked
> at it from all sides but I don't get it.
> Does anyone know how to get this working?
>
>
>
> Marco

Are you doing a GET or a POST? You're using both in your code - which
is highly unusual.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: pagination driving me insane [message #174610 is a reply to message #174609] Wed, 22 June 2011 05:02 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
On 22 jun, 04:18, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 6/21/2011 5:22 PM, Co wrote:
>
>
>
>
>
>
>
>
>
>> Hi All,
>
>> I have a page which displays accounts. On the page there are three
>> search options:
>
>> 1. sort by newest members first;
>> 2. search by country;
>> 3. search by name;
>
>> There is a limit of 10 accounts per page. If the query returns more
>> than 10  records I have to browse to the next page.
>> So I need to save the search options in the url when I go to the next
>> page. I tried the following code but it doesn't work properly:
>
>> // check if any of the three buttons were clicked
>> if(isset($_POST['listByq']) {
>
>> // did I click the search by country button
>>   if ($_POST['listByq'] == "by_country") {
>
>>      $value = $_POST['country'];   //put the country name in the
>> variable for the URL
>>      $country = $_POST['country'];
>>      $queryString = "WHERE country='$country' AND email_activated='1'";
>>      $choice = $_POST['listByq']; }  //put by_country in the variable
>> for the URL
>
>> // did I click on the searh by firstname
>>   else if ($_POST['listByq'] == "by_firstname") {
>
>>      $value = $_POST['fname'];
>>      $firstname = $_POST['fname'];
>>      $firstname = mysql_real_escape_string($firstname);
>>      $queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
>> LIKE '%$firstname%' AND email_activated='1'";
>>      $choice = $_POST['listByq'];
>
>>    // or did I click the newest members first sort order
>> } else if ($_POST['listByq'] == "newest_members") {
>
>>          $value = "";
>>    $queryString = "WHERE email_activated='1' ORDER BY id DESC";
>>    $choice = $_POST['listByq'];
>> }
>> }
>
>> // now get the values form the URL
>> if (isset($_GET['choice'])) {
>>          $choice = $_GET['choice'];
>>          $value = $_GET['value'];
>> }
>
>> // if there was anything in $choice
>> if ($choice<>  "") {
>>     if($choice = "by_country") {
>>            $country = $value;
>>        $queryString = "WHERE country='$country' AND
>> email_activated='1'";
>>    else if ($choice= "by_firstname")  {
>>        $firstname = $value;
>>        $queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
>> LIKE '%$firstname%' AND email_activated='1'";
>>        $queryMsg = "Showing Members with the name you searched for";     }
>>    else if ($choice= "newest_members")  {
>>    $queryString = "WHERE email_activated='1' ORDER BY id DESC";
>>                            }
>
>> }
>
>> The pagination looks like this:
>> $centerPages .= '&nbsp;<a href="' . $_SERVER['PHP_SELF'] . '?pn=' .
>> $add1 . '&choice=' . $choice . '&value=' . $value . '">' . $add1 .'</
>> a>  &nbsp;';
>
>> I know there must be a solution for this which works but I have looked
>> at it from all sides but I don't get it.
>> Does anyone know how to get this working?
>
>> Marco
>
> Are you doing a GET or a POST?  You're using both in your code - which
> is highly unusual.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

I know. Initially I was doing a post when I click one of the buttons.
The country search, search by name or search by newest members.
With the GET I was trying to get the values I put into the URL when I
go to the next page.
I have been struggling with this code the whole day but I can't seem
to get it right.

Marco
Re: pagination driving me insane [message #174613 is a reply to message #174610] Wed, 22 June 2011 10:34 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/22/2011 1:02 AM, Co wrote:
> On 22 jun, 04:18, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 6/21/2011 5:22 PM, Co wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> Hi All,
>>
>>> I have a page which displays accounts. On the page there are three
>>> search options:
>>
>>> 1. sort by newest members first;
>>> 2. search by country;
>>> 3. search by name;
>>
>>> There is a limit of 10 accounts per page. If the query returns more
>>> than 10 records I have to browse to the next page.
>>> So I need to save the search options in the url when I go to the next
>>> page. I tried the following code but it doesn't work properly:
>>
>>> // check if any of the three buttons were clicked
>>> if(isset($_POST['listByq']) {
>>
>>> // did I click the search by country button
>>> if ($_POST['listByq'] == "by_country") {
>>
>>> $value = $_POST['country']; //put the country name in the
>>> variable for the URL
>>> $country = $_POST['country'];
>>> $queryString = "WHERE country='$country' AND email_activated='1'";
>>> $choice = $_POST['listByq']; } //put by_country in the variable
>>> for the URL
>>
>>> // did I click on the searh by firstname
>>> else if ($_POST['listByq'] == "by_firstname") {
>>
>>> $value = $_POST['fname'];
>>> $firstname = $_POST['fname'];
>>> $firstname = mysql_real_escape_string($firstname);
>>> $queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
>>> LIKE '%$firstname%' AND email_activated='1'";
>>> $choice = $_POST['listByq'];
>>
>>> // or did I click the newest members first sort order
>>> } else if ($_POST['listByq'] == "newest_members") {
>>
>>> $value = "";
>>> $queryString = "WHERE email_activated='1' ORDER BY id DESC";
>>> $choice = $_POST['listByq'];
>>> }
>>> }
>>
>>> // now get the values form the URL
>>> if (isset($_GET['choice'])) {
>>> $choice = $_GET['choice'];
>>> $value = $_GET['value'];
>>> }
>>
>>> // if there was anything in $choice
>>> if ($choice<> "") {
>>> if($choice = "by_country") {
>>> $country = $value;
>>> $queryString = "WHERE country='$country' AND
>>> email_activated='1'";
>>> else if ($choice= "by_firstname") {
>>> $firstname = $value;
>>> $queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
>>> LIKE '%$firstname%' AND email_activated='1'";
>>> $queryMsg = "Showing Members with the name you searched for"; }
>>> else if ($choice= "newest_members") {
>>> $queryString = "WHERE email_activated='1' ORDER BY id DESC";
>>> }
>>
>>> }
>>
>>> The pagination looks like this:
>>> $centerPages .= '&nbsp;<a href="' . $_SERVER['PHP_SELF'] . '?pn=' .
>>> $add1 . '&choice=' . $choice . '&value=' . $value . '">' . $add1 .'</
>>> a> &nbsp;';
>>
>>> I know there must be a solution for this which works but I have looked
>>> at it from all sides but I don't get it.
>>> Does anyone know how to get this working?
>>
>>> Marco
>>
>> Are you doing a GET or a POST? You're using both in your code - which
>> is highly unusual.
>>
>
> I know. Initially I was doing a post when I click one of the buttons.
> The country search, search by name or search by newest members.
> With the GET I was trying to get the values I put into the URL when I
> go to the next page.
> I have been struggling with this code the whole day but I can't seem
> to get it right.
>
> Marco

So, make up your mind. Do GET or POST - don't try to do both.

And once again - look at what you have in your $_GET and $_POST arrays,
and use them to trace through the code. Figure out what it's doing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: pagination driving me insane [message #174615 is a reply to message #174613] Wed, 22 June 2011 12:50 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
Jerry,

i need the POST to search in my members accounts.
The problem is that PHP loses the query I run when I goto the next
page.
I preferred using a session variable but I wasn't able to get rit of
the variable after I filled it. So everytime when I come back to the
page it will automatically use the session variable again.
Or is there a way to clear the session variable when I load the page?

Marco


>> Marco
>
> So, make up your mind.  Do GET or POST - don't try to do both.
>
> And once again - look at what you have in your $_GET and $_POST arrays,
> and use them to trace through the code.  Figure out what it's doing.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
>
>
Re: pagination driving me insane [message #174617 is a reply to message #174615] Wed, 22 June 2011 14:54 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/22/2011 8:50 AM, Co wrote:
>>> Marco
>>
>> So, make up your mind. Do GET or POST - don't try to do both.
>>
>> And once again - look at what you have in your $_GET and $_POST arrays,
>> and use them to trace through the code. Figure out what it's doing.
>>
> Jerry,
>
> i need the POST to search in my members accounts.
> The problem is that PHP loses the query I run when I goto the next
> page.
> I preferred using a session variable but I wasn't able to get rit of
> the variable after I filled it. So everytime when I come back to the
> page it will automatically use the session variable again.
> Or is there a way to clear the session variable when I load the page?
>
> Marco
>
>

<Top posting fixed>

No, it's no longer there because the browser didn't send it. PHP didn't
lose anything. From the browser's point of view, each page is a new
request to the server, and the browser sends only what you tell it to send.

What you need to do is determine if this a new search or a continuation
of the previous search (i.e. display the next page). If the former,
clear your old $_SESSION values (if any) and put new ones in there and
display the first page. If the latter, use the data stored in the
$_SESSION and display the next page of the search.

There are any number of ways to determine if it is a continuation page;
i.e. the $_GET or $_POST value has "page=next" or "page=3" in it; the
current page number is in a hidden field in the form or similar. A new
search wouldn't have those values.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: pagination driving me insane [message #174622 is a reply to message #174617] Wed, 22 June 2011 16:57 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
On 22 jun, 17:54, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 6/22/2011 8:50 AM, Co wrote:>>> Marco
>
>>> So, make up your mind.  Do GET or POST - don't try to do both.
>
>>> And once again - look at what you have in your $_GET and $_POST arrays,
>>> and use them to trace through the code.  Figure out what it's doing.
>
>  > Jerry,
>  >
>  > i need the POST to search in my members accounts.
>  > The problem is that PHP loses the query I run when I goto the next
>  > page.
>  > I preferred using a session variable but I wasn't able to get rit of
>  > the variable after I filled it. So everytime when I come back to the
>  > page it will automatically use the session variable again.
>  > Or is there a way to clear the session variable when I load the page?
>  >
>  > Marco
>  >
>  >
>
> <Top posting fixed>
>
> No, it's no longer there because the browser didn't send it.  PHP didn't
> lose anything.  From the browser's point of view, each page is a new
> request to the server, and the browser sends only what you tell it to send.
>
> What you need to do is determine if this a new search or a continuation
> of the previous search (i.e. display the next page).  If the former,
> clear your old $_SESSION values (if any) and put new ones in there and
> display the first page.  If the latter, use the data stored in the
> $_SESSION and display the next page of the search.
>
> There are any number of ways to determine if it is a continuation page;
> i.e. the $_GET or $_POST value has "page=next" or "page=3" in it; the
> current page number is in a hidden field in the form or similar.  A new
> search wouldn't have those values.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
>
>

I will try to work on that.
But can I clear the session before I open the page so that an
older session that I used ealier will be cleared until I hit the
submit button? I don't want to clear the whole sessions just the one
variable.

Marco
Re: pagination driving me insane [message #174624 is a reply to message #174622] Wed, 22 June 2011 17:17 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/22/2011 12:57 PM, Co wrote:
> On 22 jun, 17:54, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 6/22/2011 8:50 AM, Co wrote:>>> Marco
>>
>>>> So, make up your mind. Do GET or POST - don't try to do both.
>>
>>>> And once again - look at what you have in your $_GET and $_POST arrays,
>>>> and use them to trace through the code. Figure out what it's doing.
>>
>>> Jerry,
>>>
>>> i need the POST to search in my members accounts.
>>> The problem is that PHP loses the query I run when I goto the next
>>> page.
>>> I preferred using a session variable but I wasn't able to get rit of
>>> the variable after I filled it. So everytime when I come back to the
>>> page it will automatically use the session variable again.
>>> Or is there a way to clear the session variable when I load the page?
>>>
>>> Marco
>>>
>>>
>>
>> <Top posting fixed>
>>
>> No, it's no longer there because the browser didn't send it. PHP didn't
>> lose anything. From the browser's point of view, each page is a new
>> request to the server, and the browser sends only what you tell it to send.
>>
>> What you need to do is determine if this a new search or a continuation
>> of the previous search (i.e. display the next page). If the former,
>> clear your old $_SESSION values (if any) and put new ones in there and
>> display the first page. If the latter, use the data stored in the
>> $_SESSION and display the next page of the search.
>>
>> There are any number of ways to determine if it is a continuation page;
>> i.e. the $_GET or $_POST value has "page=next" or "page=3" in it; the
>> current page number is in a hidden field in the form or similar. A new
>> search wouldn't have those values.
>>
>
> I will try to work on that.
> But can I clear the session before I open the page so that an
> older session that I used ealier will be cleared until I hit the
> submit button? I don't want to clear the whole sessions just the one
> variable.
>
> Marco

You can unset() any element you want in the $_SESSION array. But you
can't do ANYTHING until the user requests a page - your code doesn't get
invoked until that time.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: pagination driving me insane [message #174644 is a reply to message #174624] Thu, 23 June 2011 17:24 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
On 22 jun, 19:17, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 6/22/2011 12:57 PM, Co wrote:
>
>
>
>
>
>
>
>
>
>> On 22 jun, 17:54, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>>> On 6/22/2011 8:50 AM, Co wrote:>>>  Marco
>
>>>> > So, make up your mind.  Do GET or POST - don't try to do both.
>
>>>> > And once again - look at what you have in your $_GET and $_POST arrays,
>>>> > and use them to trace through the code.  Figure out what it's doing.
>
>>>   >  Jerry,
>
>>>   >  i need the POST to search in my members accounts.
>>>   >  The problem is that PHP loses the query I run when I goto the next
>>>   >  page.
>>>   >  I preferred using a session variable but I wasn't able to get rit of
>>>   >  the variable after I filled it. So everytime when I come back to the
>>>   >  page it will automatically use the session variable again.
>>>   >  Or is there a way to clear the session variable when I load the page?
>
>>>   >  Marco
>
>>> <Top posting fixed>
>
>>> No, it's no longer there because the browser didn't send it.  PHP didn't
>>> lose anything.  From the browser's point of view, each page is a new
>>> request to the server, and the browser sends only what you tell it to send.
>
>>> What you need to do is determine if this a new search or a continuation
>>> of the previous search (i.e. display the next page).  If the former,
>>> clear your old $_SESSION values (if any) and put new ones in there and
>>> display the first page.  If the latter, use the data stored in the
>>> $_SESSION and display the next page of the search.
>
>>> There are any number of ways to determine if it is a continuation page;
>>> i.e. the $_GET or $_POST value has "page=next" or "page=3" in it; the
>>> current page number is in a hidden field in the form or similar.  A new
>>> search wouldn't have those values.
>
>> I will try to work on that.
>> But can I clear the session before I open the page so that an
>> older session that I used ealier will be cleared until I hit the
>> submit button? I don't want to clear the whole sessions just the one
>> variable.
>
>> Marco
>
> You can unset() any element you want in the $_SESSION array.  But you
> can't do ANYTHING until the user requests a page - your code doesn't get
> invoked until that time.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

I have been trying the following code but I get an error when I click
the next page on my form:

if(isset($_POST['listByq']) && $_POST['listByq'] != "add") {
unset($_SESSION['listByq']);
$option = "";
$_SESSION['listByq'] = $_POST['listByq'];
}

if(isset($_SESSION['listByq'])) {
$option = $_SESSION['listByq'];
if ($option == "by_country") {

$country = $_POST['country'];

$queryString = "WHERE country='$country' AND email_activated='1'";
$queryMsg = "Showing Members from the country you searched for";

} else if ($option == "by_firstname") {

$firstname = $_POST['fname'];
$firstname = stripslashes($firstname);
$firstname = strip_tags($firstname);
$firstname = eregi_replace("`", "", $firstname);
$firstname = mysql_real_escape_string($firstname);
$queryString = "WHERE rank LIKE '%$firstname%' OR firstname LIKE '%
$firstname%' OR lastname LIKE '%$firstname%' AND email_activated='1'";
$queryMsg = "Showing Members with the name you searched for";

} else if ($option == "newest_members") {

$queryString = "WHERE email_activated='1' ORDER BY id DESC";
$queryMsg = "Showing Newest to Oldest Members";
}

} // end of if(isset($_SESSION....


Notice: Undefined index: fname

When the POST has been done there is no problem but after that it
doesn't recognise fname or country anymore.

Marco
Re: pagination driving me insane [message #174645 is a reply to message #174644] Thu, 23 June 2011 17:27 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/23/2011 1:24 PM, Co wrote:
> On 22 jun, 19:17, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 6/22/2011 12:57 PM, Co wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On 22 jun, 17:54, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>>>> On 6/22/2011 8:50 AM, Co wrote:>>> Marco
>>
>>>> >> So, make up your mind. Do GET or POST - don't try to do both.
>>
>>>> >> And once again - look at what you have in your $_GET and $_POST arrays,
>>>> >> and use them to trace through the code. Figure out what it's doing.
>>
>>>> > Jerry,
>>
>>>> > i need the POST to search in my members accounts.
>>>> > The problem is that PHP loses the query I run when I goto the next
>>>> > page.
>>>> > I preferred using a session variable but I wasn't able to get rit of
>>>> > the variable after I filled it. So everytime when I come back to the
>>>> > page it will automatically use the session variable again.
>>>> > Or is there a way to clear the session variable when I load the page?
>>
>>>> > Marco
>>
>>>> <Top posting fixed>
>>
>>>> No, it's no longer there because the browser didn't send it. PHP didn't
>>>> lose anything. From the browser's point of view, each page is a new
>>>> request to the server, and the browser sends only what you tell it to send.
>>
>>>> What you need to do is determine if this a new search or a continuation
>>>> of the previous search (i.e. display the next page). If the former,
>>>> clear your old $_SESSION values (if any) and put new ones in there and
>>>> display the first page. If the latter, use the data stored in the
>>>> $_SESSION and display the next page of the search.
>>
>>>> There are any number of ways to determine if it is a continuation page;
>>>> i.e. the $_GET or $_POST value has "page=next" or "page=3" in it; the
>>>> current page number is in a hidden field in the form or similar. A new
>>>> search wouldn't have those values.
>>
>>> I will try to work on that.
>>> But can I clear the session before I open the page so that an
>>> older session that I used ealier will be cleared until I hit the
>>> submit button? I don't want to clear the whole sessions just the one
>>> variable.
>>
>>> Marco
>>
>> You can unset() any element you want in the $_SESSION array. But you
>> can't do ANYTHING until the user requests a page - your code doesn't get
>> invoked until that time.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> I have been trying the following code but I get an error when I click
> the next page on my form:
>
> if(isset($_POST['listByq'])&& $_POST['listByq'] != "add") {
> unset($_SESSION['listByq']);
> $option = "";
> $_SESSION['listByq'] = $_POST['listByq'];
> }
>
> if(isset($_SESSION['listByq'])) {
> $option = $_SESSION['listByq'];
> if ($option == "by_country") {
>
> $country = $_POST['country'];
>
> $queryString = "WHERE country='$country' AND email_activated='1'";
> $queryMsg = "Showing Members from the country you searched for";
>
> } else if ($option == "by_firstname") {
>
> $firstname = $_POST['fname'];
> $firstname = stripslashes($firstname);
> $firstname = strip_tags($firstname);
> $firstname = eregi_replace("`", "", $firstname);
> $firstname = mysql_real_escape_string($firstname);
> $queryString = "WHERE rank LIKE '%$firstname%' OR firstname LIKE '%
> $firstname%' OR lastname LIKE '%$firstname%' AND email_activated='1'";
> $queryMsg = "Showing Members with the name you searched for";
>
> } else if ($option == "newest_members") {
>
> $queryString = "WHERE email_activated='1' ORDER BY id DESC";
> $queryMsg = "Showing Newest to Oldest Members";
> }
>
> } // end of if(isset($_SESSION....
>
>
> Notice: Undefined index: fname
>
> When the POST has been done there is no problem but after that it
> doesn't recognise fname or country anymore.
>
> Marco

That's because they weren't in the form, so the browser can't send them.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: pagination driving me insane [message #174647 is a reply to message #174645] Thu, 23 June 2011 18:08 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
On 23 jun, 19:27, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 6/23/2011 1:24 PM, Co wrote:
>
>
>
>
>
>
>
>
>
>> On 22 jun, 19:17, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>>> On 6/22/2011 12:57 PM, Co wrote:
>
>>>> On 22 jun, 17:54, Jerry Stuckle<jstuck...@attglobal.net>    wrote:
>>>> > On 6/22/2011 8:50 AM, Co wrote:>>>    Marco
>
>>>> >>> So, make up your mind.  Do GET or POST - don't try to do both.
>
>>>> >>> And once again - look at what you have in your $_GET and $_POST arrays,
>>>> >>> and use them to trace through the code.  Figure out what it's doing.
>
>>>> >    >    Jerry,
>
>>>> >    >    i need the POST to search in my members accounts.
>>>> >    >    The problem is that PHP loses the query I run when I goto the next
>>>> >    >    page.
>>>> >    >    I preferred using a session variable but I wasn't able to get rit of
>>>> >    >    the variable after I filled it. So everytime when I come back to the
>>>> >    >    page it will automatically use the session variable again.
>>>> >    >    Or is there a way to clear the session variable when I load the page?
>
>>>> >    >    Marco
>
>>>> > <Top posting fixed>
>
>>>> > No, it's no longer there because the browser didn't send it.  PHP didn't
>>>> > lose anything.  From the browser's point of view, each page is a new
>>>> > request to the server, and the browser sends only what you tell it to send.
>
>>>> > What you need to do is determine if this a new search or a continuation
>>>> > of the previous search (i.e. display the next page).  If the former,
>>>> > clear your old $_SESSION values (if any) and put new ones in there and
>>>> > display the first page.  If the latter, use the data stored in the
>>>> > $_SESSION and display the next page of the search.
>
>>>> > There are any number of ways to determine if it is a continuation page;
>>>> > i.e. the $_GET or $_POST value has "page=next" or "page=3" in it; the
>>>> > current page number is in a hidden field in the form or similar.  A new
>>>> > search wouldn't have those values.
>
>>>> I will try to work on that.
>>>> But can I clear the session before I open the page so that an
>>>> older session that I used ealier will be cleared until I hit the
>>>> submit button? I don't want to clear the whole sessions just the one
>>>> variable.
>
>>>> Marco
>
>>> You can unset() any element you want in the $_SESSION array.  But you
>>> can't do ANYTHING until the user requests a page - your code doesn't get
>>> invoked until that time.
>
>>> --
>>> ==================
>>> Remove the "x" from my email address
>>> Jerry Stuckle
>>> JDS Computer Training Corp.
>>> jstuck...@attglobal.net
>>> ==================
>
>> I have been trying the following code but I get an error when I click
>> the next page on my form:
>
>> if(isset($_POST['listByq'])&&  $_POST['listByq'] != "add") {
>>      unset($_SESSION['listByq']);
>>    $option = "";
>>    $_SESSION['listByq'] = $_POST['listByq'];
>> }
>
>> if(isset($_SESSION['listByq'])) {
>>     $option = $_SESSION['listByq'];
>>   if ($option == "by_country") {
>
>>    $country = $_POST['country'];
>
>>      $queryString = "WHERE country='$country' AND email_activated='1'";
>>      $queryMsg = "Showing Members from the country you searched for";
>
>> } else if ($option == "by_firstname") {
>
>>    $firstname = $_POST['fname'];
>>    $firstname = stripslashes($firstname);
>>      $firstname = strip_tags($firstname);
>>    $firstname = eregi_replace("`", "", $firstname);
>>    $firstname = mysql_real_escape_string($firstname);
>>      $queryString = "WHERE rank LIKE '%$firstname%' OR firstname LIKE '%
>> $firstname%' OR lastname LIKE '%$firstname%' AND email_activated='1'";
>>      $queryMsg = "Showing Members with the name you searched for";
>
>> } else if ($option == "newest_members") {
>
>>      $queryString = "WHERE email_activated='1' ORDER BY id DESC";
>>    $queryMsg = "Showing Newest to Oldest Members";
>> }
>
>> }  // end of if(isset($_SESSION....
>
>> Notice: Undefined index: fname
>
>> When the POST has been done there is no problem but after that it
>> doesn't recognise fname or country anymore.
>
>> Marco
>
> That's because they weren't in the form, so the browser can't send them.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

Hmmm,

I created a second SESSION variable like $_SESSION['ValueByq']
this one holds either the country value or the fname value.

if(isset($_POST['listByq']) && $_POST['listByq'] != "add") {
unset($_SESSION['listByq']);
unset($_SESSION['valueByq']);
$option = "";
$_SESSION['listByq'] = $_POST['listByq'];
if(isset($_POST['fname'])) { $_SESSION['valueByq'] =
$_POST['fname']; }
if(isset($_POST['country'])) { $_SESSION['valueByq'] =
$_POST['country']; }
}

The only thing I don't know is what will happen when i login, go to
this page and the
session variables don't exist yet?

Marco
Re: pagination driving me insane [message #174649 is a reply to message #174647] Thu, 23 June 2011 19:03 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/23/2011 2:08 PM, Co wrote:
> On 23 jun, 19:27, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 6/23/2011 1:24 PM, Co wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On 22 jun, 19:17, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>>>> On 6/22/2011 12:57 PM, Co wrote:
>>
>>>> > On 22 jun, 17:54, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>>>> >> On 6/22/2011 8:50 AM, Co wrote:>>> Marco
>>
>>>> >>>> So, make up your mind. Do GET or POST - don't try to do both.
>>
>>>> >>>> And once again - look at what you have in your $_GET and $_POST arrays,
>>>> >>>> and use them to trace through the code. Figure out what it's doing.
>>
>>>> >> > Jerry,
>>
>>>> >> > i need the POST to search in my members accounts.
>>>> >> > The problem is that PHP loses the query I run when I goto the next
>>>> >> > page.
>>>> >> > I preferred using a session variable but I wasn't able to get rit of
>>>> >> > the variable after I filled it. So everytime when I come back to the
>>>> >> > page it will automatically use the session variable again.
>>>> >> > Or is there a way to clear the session variable when I load the page?
>>
>>>> >> > Marco
>>
>>>> >> <Top posting fixed>
>>
>>>> >> No, it's no longer there because the browser didn't send it. PHP didn't
>>>> >> lose anything. From the browser's point of view, each page is a new
>>>> >> request to the server, and the browser sends only what you tell it to send.
>>
>>>> >> What you need to do is determine if this a new search or a continuation
>>>> >> of the previous search (i.e. display the next page). If the former,
>>>> >> clear your old $_SESSION values (if any) and put new ones in there and
>>>> >> display the first page. If the latter, use the data stored in the
>>>> >> $_SESSION and display the next page of the search.
>>
>>>> >> There are any number of ways to determine if it is a continuation page;
>>>> >> i.e. the $_GET or $_POST value has "page=next" or "page=3" in it; the
>>>> >> current page number is in a hidden field in the form or similar. A new
>>>> >> search wouldn't have those values.
>>
>>>> > I will try to work on that.
>>>> > But can I clear the session before I open the page so that an
>>>> > older session that I used ealier will be cleared until I hit the
>>>> > submit button? I don't want to clear the whole sessions just the one
>>>> > variable.
>>
>>>> > Marco
>>
>>>> You can unset() any element you want in the $_SESSION array. But you
>>>> can't do ANYTHING until the user requests a page - your code doesn't get
>>>> invoked until that time.
>>
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck...@attglobal.net
>>>> ==================
>>
>>> I have been trying the following code but I get an error when I click
>>> the next page on my form:
>>
>>> if(isset($_POST['listByq'])&& $_POST['listByq'] != "add") {
>>> unset($_SESSION['listByq']);
>>> $option = "";
>>> $_SESSION['listByq'] = $_POST['listByq'];
>>> }
>>
>>> if(isset($_SESSION['listByq'])) {
>>> $option = $_SESSION['listByq'];
>>> if ($option == "by_country") {
>>
>>> $country = $_POST['country'];
>>
>>> $queryString = "WHERE country='$country' AND email_activated='1'";
>>> $queryMsg = "Showing Members from the country you searched for";
>>
>>> } else if ($option == "by_firstname") {
>>
>>> $firstname = $_POST['fname'];
>>> $firstname = stripslashes($firstname);
>>> $firstname = strip_tags($firstname);
>>> $firstname = eregi_replace("`", "", $firstname);
>>> $firstname = mysql_real_escape_string($firstname);
>>> $queryString = "WHERE rank LIKE '%$firstname%' OR firstname LIKE '%
>>> $firstname%' OR lastname LIKE '%$firstname%' AND email_activated='1'";
>>> $queryMsg = "Showing Members with the name you searched for";
>>
>>> } else if ($option == "newest_members") {
>>
>>> $queryString = "WHERE email_activated='1' ORDER BY id DESC";
>>> $queryMsg = "Showing Newest to Oldest Members";
>>> }
>>
>>> } // end of if(isset($_SESSION....
>>
>>> Notice: Undefined index: fname
>>
>>> When the POST has been done there is no problem but after that it
>>> doesn't recognise fname or country anymore.
>>
>>> Marco
>>
>> That's because they weren't in the form, so the browser can't send them.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Hmmm,
>
> I created a second SESSION variable like $_SESSION['ValueByq']
> this one holds either the country value or the fname value.
>
> if(isset($_POST['listByq'])&& $_POST['listByq'] != "add") {
> unset($_SESSION['listByq']);
> unset($_SESSION['valueByq']);
> $option = "";
> $_SESSION['listByq'] = $_POST['listByq'];
> if(isset($_POST['fname'])) { $_SESSION['valueByq'] =
> $_POST['fname']; }
> if(isset($_POST['country'])) { $_SESSION['valueByq'] =
> $_POST['country']; }
> }
>
> The only thing I don't know is what will happen when i login, go to
> this page and the
> session variables don't exist yet?
>
> Marco

You need to test to see if they are set or not using isset(), like you
are with your $_POST values. And if they aren't set, take the
appropriate action.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IP address and empty $_FILES
Next Topic: Command line cannot fwrite, browser can
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 09:05:29 GMT 2024

Total time taken to generate the page: 0.02441 seconds