close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Hi I have a database search results page that I would like to paginate but as it moves from the first page to the next page it loses the value of the search term. s <?php $search_rs = new WA_MySQLi_RS("search_rs",$connection,10); $search_rs->setQue

Thread began 11/29/2014 11:10 am by Andrew | Last modified 12/02/2014 2:56 pm by Jason Byrnes | 2650 views | 11 replies |

Andrew

Hi I have a database search results page that I would like to paginate but as it moves from the first page to the next page it loses the value of the search term. s <?php $search_rs = new WA_MySQLi_RS("search_rs",$connection,10); $search_rs->setQuery("SE

Hi

I have a database search results page that I would like to paginate but as it moves from the first page to the next page it loses the value of the search term.

ie

The recordset is
<?php
$search_rs = new WA_MySQLi_RS("search_rs",$connection,10);
$search_rs->setQuery("SELECT * FROM items WHERE items.itemTitle LIKE '%".$_POST['search']."%' ORDER BY items.itemTitle ASC");
$search_rs->execute();
?>
with 'search' being POSTed from another page.

This successfully produces a list of 10 results using ...

<?php
while(!$search_rs->atEnd()) {
?>

<tr>
<td><?php echo($search_rs->getColumnVal("itemNo")); ?></td>
<td><?php echo($search_rs->getColumnVal("itemTitle")); ?></div></td>
</tr>

<?php
$search_rs->moveNext();
}
$search_rs->moveFirst();
?>

Adding and clicking the link

<a href="<?php echo $search_rs->getNextPageLink(); ?>">Next</a>

before the results listing gives "undefined index" for the query ie it has lost the 'search' value.

Hope that this makes sense.

Would be grateful for any suggestions to solve this.

Thanks

Andrew

Sign in to reply to this post

Jason ByrnesWebAssist

change the next link:

<a href="<?php echo $search_rs->getNextPageLink(); ?>">Next</a>



to:

<a href="<?php echo $search_rs->getNextPageLink(); ?><?php echo(isset($_POST['search'])?"&". $_POST['search']:""); ?>">Next</a>




then add the following at line 1:

<?php
if(isset($_GET['search'])) {
$_POST['search'] = $_GET['search'];
}
?>
Sign in to reply to this post

Andrew

Hi

I've done as you said - copied and pasted.

It lists the first ten results correctly and then again on page two loses the value of the variable and lists the entire database.

Notice: Undefined index: search in C:\wamp_php5_5\www\sheffieldarchives\database_admin\admin_search_library_results.php on line 9

where line 9 is

$search_rs->setQuery("SELECT * FROM items WHERE items.itemTitle LIKE '%".$_POST['search']."%' ORDER BY items.itemTitle ASC");

(Point of clarification - I've no knowledge of php - I've added

<?php
if(isset($_GET['search'])) {
$_POST['search'] = $_GET['search'];
}
?>

immediately above the pagination code. I assume that is what you meant.

Thanks in anticipation

Andrew

Sign in to reply to this post

Jason ByrnesWebAssist

no, this code:
<?php
if(isset($_GET['search'])) {
$_POST['search'] = $_GET['search'];
}
?>

needs to go at line 1, not above the pagination.

Sign in to reply to this post

Andrew

That is where I originally placed it - but then I thought about it too much!

I have put it at Line 1 - and it has made no difference.

Sign in to reply to this post

Jason ByrnesWebAssist

I'll need to troubleshoot directly, see the private message section.


please send a link to your site where i can see the problem occur and ftp login details so I can access the site files directly to troubleshoot.

Sign in to reply to this post

Andrew

See below

Sign in to reply to this post

Jason ByrnesWebAssist

i am not able to reproduce.

I go to the search page, enter test and hit the submit button, no error.

on clicking the next button, i still don't see an error.

Sign in to reply to this post

Andrew

See below

Sign in to reply to this post

Jason ByrnesWebAssist

I see, I was looking for the error you reported, not paying attention to the results.

Sorry, the code for the next link:

<a href="<?php echo $search_rs->getNextPageLink(); ?><?php echo(isset($_POST['search'])?"&". $_POST['search']:""); ?>">Next</a>


should be:
<a href="<?php echo $search_rs->getNextPageLink(); ?><?php echo(isset($_POST['search'])?"&search=". $_POST['search']:""); ?>">Next</a>

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...