Copy link to clipboard
Copied
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?
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 record
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Yes that's exactly it - I could use a new page for the 2nd record set as a workaround or use some kind of javascript widget to open an html container with the 2nd recordset in it I guess but it seems a liitle like overkill as I like the simplicity of the current page. Another solution would be to put a dummy set of data in so that I always know I'm going to have that record in there but thank you for jogging me into a solution I have that works for this page which now looks much better than a blank table. I appreciate your time.
Copy link to clipboard
Copied
Actually, from a user perspective, a dummy set of data might not be a bad idea - it may avoid any confusion like, like why is this particular record detail showing and not another?
Another possible solution would take the opposite approach and not display anything at first. This can be easily done by selecting the entire table and apply the Show if Recordset is Not Empty server behavior. You could even teke that a step further and have a region that displays when the recordset is empty that could display anything like a simple message, static or dynamic dummy table.
Copy link to clipboard
Copied
Yes - good point - it also gives a visual cue as to where the data is pulled from to make sure they enter all relevant details. Thanks again
Copy link to clipboard
Copied
You're very welcome.