• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Search pages

Community Beginner ,
Apr 06, 2009 Apr 06, 2009

Copy link to clipboard

Copied

I have a master detail page which is sorted and shows 30 records at a time.  One of the columns holds Session records for tennis instruction.  The client wishes to be able to click a button to display only selected items from that column.  I figured a Search page is now in order.

Here's what I've done so far to accomplish this:

Duplicated admin_master.php (page where all the records currently display), named it admin_results.php (page to hold the results) so it would look like the admin_master.php page but with filtered results.

<<admin_master.php>>

Added a form to admin_master.php

Form name is SearchForm, Action is admin_results.php

Added List/Menu form item, name = Session

Added every existing records that Session has in it b/c I couldn't get them to auto-populate using Dynamic (will address later)

Added Submit button

Saved and Uploaded

<<admin_results.php>>

Altered Recordset rs_master, All columns, Filter: Session = URL Parameter Session

Tested Filter by clicking Test and entered a known good record.  Comes up with proper number of records everytime

Saved and Uploaded

<<testing on the website>>

Go to admin_master.php and select one of the ListMenu Items and click Submit

Get following error:  Fatal error: Can't use function return value in write context in /home/shortcou/public_html/admin_results.php on line 133

Line 133 from admin_results.php

$totalPages_rs_master = ceil($totalRows_rs_master/$maxRows_rs_master) = 30;

* Note:  The admin_results.php page was copied from admin_master.php which had the First, Next, Previous, Last behaviors but I removed those cleanly via the (-) on the Behaviors tab.

**  If I created a new page for the results it works fine, but I need to understand why this particular error (which shows up on numerouse pages after making changes) always occurs and how to fix it so I don't have to keep building new pages.

TOPICS
Server side applications

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2009 Apr 06, 2009

Copy link to clipboard

Copied

$totalPages_rs_master = ceil($totalRows_rs_master/$maxRows_rs_master) = 30;

Not sure that I follow everything you're trying to do, but the preceding line is logical nonsense. $totalPages_rs_master must be either 30 or the ceiling of $totalRows_rs_master divided by $maxRows_rs_master, but it can't be both.

I suspect this is what you mean:

$totalPages_rs_master = ceil($totalRows_rs_master/$maxRows_rs_master);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 06, 2009 Apr 06, 2009

Copy link to clipboard

Copied

Yes I agree.  I have frequent errors on many pages after changing things and they all point to the line (I think someone else in this forum just posted a similar issue).  The first time it happened I had changed the number of records displayed from 10 to 20 and got that error.  Deleted that line that the error referrenced and then it worked.  I've grown to learn that DW sometimes does not always clean out the code after a change, but you have to know where to look.

So on to my next question on Searching:

How do I get the List/Menu to auto-populate with the items from the Session field in rs_master?

From the List/Menu properties:

I choose Options from recordset, then choose the recordset

Values: Session

Labels: Session

Select value equal to: <empty> but I've tried selecting field called Session

Thanks,

Steve

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

I have frequent errors on many pages after changing things

It sounds as though you're making the classic mistake of deleting dynamic objects in Design view instead of using the Server Behaviors panel to remove things cleanly. Select the dynamic object you want to remove in the Server Behaviors panel, and click the minus button. Page navigation inserts a lot of dynamic objects, and you need to make sure you remove all of them.

How do I get the List/Menu to auto-populate with the items from the Session field in rs_master?

You have identified the correct steps. "Select value equal to" is for setting the selected="selected" attribute in the <option> tag that you want displayed - this is typically used for an update form, where you want to display the currently stored value.

If the menu isn't being automatically populated, it sounds as though there are no results. This could happen if you have already used a repeat region to loop through the recordset results. If that's the case, you need to reset the recordset using mysql_data_seek() like this:

mysql_data_seek($rs_master, 0);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

That line was already in there.

I made new recordset (rs_search) for the Item/Menu form and I'm getting closer.

What happens now is that when I view the admin_master.php page, I see all the records (instead of 30 at time), and the Item / Menu list is populated 75 entries of repeated records from the Session field.  In other words I would expect to see in the list:

Brookeside I

Brookeside II

Brookeside III

Waterton I

Waterton II

Waterton III

Summer Camp I

Summer Camp II

Instead there are 75 instances of those above records in the list, like it's grabbing each Session record value for each record of which there are 75 records in the database.

Question, with regards to the Dynamic button, should both Values and Labels be the same thing?  I don't understand why you would need both.  Also can you mix static entries with dynamic ones?  I have both Values and Labels set to Session.  Also do I need some sort of filter on the new recordset since I'm no longer getting the 30 records at a time?

Steve

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

Instead there are 75 instances of those above records in the list, like it's grabbing each Session record value for each record of which there are 75 records in the database.

Use the DISTINCT keyword in your SQL:

SELECT DISTINCT Session

FROM tableName

with regards to the Dynamic button, should both Values and Labels be the same thing?  I don't understand why you would need both

They don't need to be. The value could be a code number for the database or the item's primary key. The label is what you want to show the world. If you omit the values, the value in the label is taken instead.

Also can you mix static entries with dynamic ones?

Yes. It's quite common to have a static value at the top saying "Please make a selection".

Also do I need some sort of filter on the new recordset since I'm no longer getting the 30 records at a time?

Yes, you probably do. If you're using a recordset navigation bar, you could use the same code to add a LIMIT clause to the end of the SQL query. The variable that adds the LIMIT clause is called $query_limit_recordsetName.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

Awesome David thanks yet again.  Now to make things a bit more tricky.  I have the "results" page which populates with the correct filtered results from the Session dropdown on the previous "search" page.  What I'd really love to happen would be once they arrive at the filtered results page, to include the same search dropdown on that page so that they could keep searching with different Session options rather than having to click back to the "search" page, AND at the same time, if they edit an item on the "results" page, have it return back to that exact page, not the "search" page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

The impossible we do today. Miracles take a little longer.

Probably what you need is Ajax to connect to the database in the background. You are now getting into a complex field about which I know some theory, but have never attempted myself.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

I hear ya.  OK, at least is there a way to keep the filtered results page from going back to the main search page once a record has been written using some sort of variable or URL parameter in a recordset or is that also AJAX territory?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

Yes, I cover this in Chapter 16 of "The Essential Guide to Dreamweaver CS4 with CSS, Ajax, and PHP".

Basically, you need to add pageNum_recordsetName and totalRows_recordsetName as URL parameters in the link back to the results page. Both are available as PHP variables called, guess what, $pageNum_recordsetName and $totalRows_recordsetName.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

Book is on it's way

So I have a main page, a results page and an updater page.  Obviously I can only return from the updater page to a single URL.  So if it's set to return to the results page, then you still have to click back to the main page.  Does this mean that I really should have two seperate updater pages - one for the main (unfiltered) results and one specifically for the edits done from the results (filtered) page?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

Not really. You should be able to control things with conditional logic (if... else).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 07, 2009 Apr 07, 2009

Copy link to clipboard

Copied

Whew, that's good to know.  Can you shed some light on the framework for that please?  Amazon says it will be about 2 weeks before the book gets here and even then you KNOW I'll have questions

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 09, 2009 Apr 09, 2009

Copy link to clipboard

Copied

As I mentioned before, Dreamweaver uses two variables to control recordset page navigation. You need to pass those values to the update page through the URL.

The link to your update page probably looks something like this:

<a href="update.php?id=<?php echo $row_recordsetName['id']; ?>">Update record</a>

Add the recordset navigation values to the link like this:

<a href="update.php?id=<?php echo $row_recordsetName['id'];

if ($pageNum_recordsetName) {

  echo "&pageNum_recordsetName=$pageNum_recordsetName&

     totalRows_recordsetName=$totalRows_recordsetName";

} ?>">Update record</a>

The Update Record server behavior preserves anything in the query string, so you'll automatically go back to the same page after updating.

Thanks for ordering the book. I'm surprised Amazon says it will take two weeks. It should be in stock.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 09, 2009 Apr 09, 2009

Copy link to clipboard

Copied

OK, I added your code to the results.php page which is the filtered subset page.  It's update link is named Edit and has a recordset called rs_master associated with it.

The code for the Edit link is as follows:

<a href="admin_updater.php?RecordID=<?php echo $row_rs_master['RecordID']; if ($pageNum_rs_master) {

  echo "&pageNum_rs_master=$pageNum_rs_master&

     totalRows_rs_master=$totalRows_rs_master";

} ?>">Edit</a>

When I click on Edit, it goes to the updater.php page and I edit the record, but it still goes back to the main.php page.

Does it matter if the recordset on the updater.php page is named something different?  It's Recordset1.

Thanks,

Steve

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 09, 2009 Apr 09, 2009

Copy link to clipboard

Copied

When I click on Edit, it goes to the updater.php page and I edit the record, but it still goes back to the main.php page.

You need to change it to go back to results.php. If you can't use the Update Record server behavior dialog box any more, change the value of $updateGoTo.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 09, 2009 Apr 09, 2009

Copy link to clipboard

Copied

Made the changes to the Update Behavior on update page to point back to results.  Now the results page is blank.  Is the problem that I have the main page with an Edit link to go to the update page AND the results page to do the same thing?  Is it getting confused or can I have two different pages pointing to an update page?

What I'd like to end up with is the main page shows all records when the user logs in, and they can edit directly from there by clicking on any of the records.  But if they use the category filter from there and end up on the results page, edit from there as well.  If they are on the main page and edit, I want them to return to the main page, if they are on the results page and edit, I want them to return to the results page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 09, 2009 Apr 09, 2009

Copy link to clipboard

Copied

That's where you need to start thinking about PHP conditional logic. Draw up a flow chart: if the user does this, I want this to happen, but if the user does something else, I want something else to happen.

I have shown you the variables that are used to control the display in recordset navigation (pageNum_recordsetName and totalRows_recordsetName). You need to follow those through the logic of your pages.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

Thanks David.  I have given this some thought and have decided on the following workflow of the admin pages. 

Main page has one form input named Search For Records, which has a List/Menu appended to.  In it are the options, All Records, and Session I, Session II, etc...

If the user chooses All Records, it takes them to the results page with all records

If the user chooses Session I, Session II, etc., it takes them to the results page with the Session they select

Everything works, except the ALL RECORDS.  I just get a blank table on the results page instead of all records.  The session filter works as before.

<< Main Page >>

List / Menu parameters

Static: Value = *, Label = All Records

Options for recordset = rs_search

Values: Session

Lables: Session

Recordsset = rs_search

SQL:

SELECT DISTINCT Session

FROM reg_capture

ORDER BY reg_capture.`Session` ASC

<< Results Page >>

Recordset = rs_results1

Columns = all records

Filter: Session = URL Parameter Session

Do I need a new recordset for the All Records somewhere? 

Help me with this and I'll be out of your hair

Steve

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

LATEST

If you're sending the user back to get all records, after updating, you need to get rid of the existing URL parameters in the query string, and replace them with your Session variable. I'm not sure how you're organizing things, but you need to build conditional logic to control the value of $updateGoTo.

if (go_to_all is clicked) {

  $updateGoTo = "results.php?Session=all";

} else {

  $updateGoTo = "results.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 06, 2009 Apr 06, 2009

Copy link to clipboard

Copied

Found the issue.

Compared new page with error page and noticed that the line 133 ($totalPages_rs_master = ceil($totalRows_rs_master/$maxRows_rs_master) = 30;) was not in the new page.

Deleted it and it works fine.

Now I need to know how to get my List to auto-populate with existing table values instead of having to manually enter them so they are always current.

Thanks,

Steve

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines