Skip to main content
Participating Frequently
September 3, 2011
Answered

Load page with a selected record

  • September 3, 2011
  • 1 reply
  • 1080 views

I have a PHP page linked to a mySql database with 2 recordets.  The first presents a simple list of records that then link to the presentation of details of those records in a table below it.  All works fine but on page load the details table is, of course, a blank shell until the user clicks on the linked url in the list that loads the record into the table.

I'd like the page to load with a sample record in it so that it looks better - preferably a random record but if not then the first in the list.  What's the simplest way to achieve that?

This topic has been closed for replies.
Correct answer Lon_Winters

Oh ok, so it appears that the first recordset is being filtered on a certain parameter? Are you displaying several records from the first recordset in a repat region? And the second table displays detail from a single record, but it should be a record contained in the first recordset. Hmmmm.  The first thing that comes to mind, is to define a variable and populate it with the ID value from the first record from the first recordset. Then use this variable as the default value in the second recordset. What I'm not sure about is this:  when you populate the variable, it will either just use the first record in the set, or since the recordset actually returns several records with different values for each ID, it may throw an error.

I generally don't like using a result from one recordset to filter a second, but I've done it - but it's only been when the first recordset only returns a single record.

1 reply

Lon_Winters
Inspiring
September 3, 2011

In the second recordset, in advanced mode, give the parameter that selects the record a default value that matches an actual record. Depending on which column you're filtering on, this would most likely be the recordID or userID.

Participating Frequently
September 3, 2011

Thank you!  That works and is much better than the blank table it loads with at the moment.  The only problem is that if that record changes in the database and is subsequently not part of the retuned list (first recordset) it wouldn't work again so I'm assuming I need to write some sql to determine the default value?

Lon_Winters
Lon_WintersCorrect answer
Inspiring
September 3, 2011

Oh ok, so it appears that the first recordset is being filtered on a certain parameter? Are you displaying several records from the first recordset in a repat region? And the second table displays detail from a single record, but it should be a record contained in the first recordset. Hmmmm.  The first thing that comes to mind, is to define a variable and populate it with the ID value from the first record from the first recordset. Then use this variable as the default value in the second recordset. What I'm not sure about is this:  when you populate the variable, it will either just use the first record in the set, or since the recordset actually returns several records with different values for each ID, it may throw an error.

I generally don't like using a result from one recordset to filter a second, but I've done it - but it's only been when the first recordset only returns a single record.