PDA

View Full Version : How to pass child list value to next page?


jeffmg279672
07-16-2010, 05:39 PM
Attached zip contains 2 pages - review_add.php which contains the dynamic dropdowns, and add_review.php. I want to be able to make a selection from the parent list, then select from the child list (which all works fine) then pass the selected item from the child list into a text field on the second page when "Submit" is pressed. How can I do this?

Dave Buchholz
07-17-2010, 05:44 AM
Assuming that you are talking about this field

<input name="vetname" type="text" id="vetname" value="<?php echo $row_Child['practicename']; ?>" size="35" />


then you need to filter your recordset by the value posted from the child select list on the previous page.

To do this open up your recordset in Dreamweaver in simple view and from the filter menu choose the id of the recordset then choose Form Variable from the drop down below that and type the name of your form field into the text box, in this case child. Save your changes and try it in a browser. the field vetname should now contain the practisename after the previous page is submitted.

jeffmg279672
07-17-2010, 10:35 AM
Many thanks, Dave - that really helped, now working fine, thanks. I now need to get the rest of the fields on that second page inserting to the db and all will be good. Appreciate your assistance.

Dave Buchholz
07-17-2010, 12:17 PM
no worries, it really is easy once you know how.

for database inserts you can use the data assist wizard available in the server behaviours panel or the standard dreamweaver insert behaviour, either will get you going.

jeffmg279672
07-17-2010, 01:33 PM
I thought I'd give it a whirl and add some insert behaviours as suggested, so created two more recordsets - one for the comments to insert into my reviews table, and the other to insert the reviewers' details into the reviewers table. I then tried testing it locally and I got a fatal error message; a quick search on here indicated that the include call for the DA App Builder file had been inserted too low down the page - it had, so I moved it up under the include call for the Connections file. I ran through the add review procedure using my local server, and the review was added to the db and I was redirected to the "thanks" page as anticipated, so I thought I'd cracked it, so I tried adding a second review, and got this error:
Duplicate entry '0' for key 2

I had no idea what this meant, so I searched on here and decided that it had something to do with the fact that the practice_id number is being added to the table as '0' each time, which is why the second review wasn't added. In other words, the practice_id isn't being passed through, which means that the review isn't linked to the correct practice, so I need to sort that somehow. I presume this is a similar thing to needing to pass the child list value (above)? I've just manually added the correct practice id number to the reviews table, and then added another dummy review and it's inserted that into "reviews" perfectly, but again with the practice_id '0'. Any suggestions how to ensure that the correct practice_id is pulled from the parent/child drop-downs and inserted into the "reviews" table?

Dave Buchholz
07-19-2010, 10:22 AM
post your current pages and I'll have a look and see if I can point out where you are going wrong

jeffmg279672
07-19-2010, 11:12 AM
Thanks Dave, attached zip contains the page with the drop-downs and the page that's giving me trouble. Wasn't sure if you wanted the db as well so have included that in the zip file.

Dave Buchholz
07-19-2010, 01:06 PM
I'll take a look in the morning for you

jeffmg279672
07-19-2010, 02:15 PM
Many thanks, appreciate it.

Dave Buchholz
07-21-2010, 01:22 AM
I ran through the add review procedure using my local server, and the review was added to the db and I was redirected to the "thanks" page as anticipated, so I thought I'd cracked it, so I tried adding a second review, and got this error:
Duplicate entry '0' for key 2

Jeff,

you are correct the error you are seeing is due to the fact that you are not inserting the practise_id into the table reviews, to solve this issue add a hidden field to your current form like so:

<input type="hidden" id="practiseID" name="practiseID" value="<?php echo $_POST['child'];" />


and then use this form in your database insert.

There is potentially another issue though as you have a field reviewers_id which will never get a value the way you have things set up currently as the standard dreamweaver database insert doesn't have an inbuilt method of creating a variable (session or global) that you can use to get the reviewers id from the insert into the reviewers table. It is possible to hand code a solution to this but I suspect that would not be your preferred option so if you have data assist you can get around this very easily by using the data assist insert server behaviour to do the insert to the reviewers table first with a blank redirect, this creates a session variable for the id of the record created that you can then use in the 2nd insert to the reviews table.

Hope that makes sense.

jeffmg279672
07-21-2010, 02:23 AM
Dave - thanks for this. I've added the hidden field to the form, but I'm a bit puzzled by the insert to the reviewers table. I've got two insert record behaviours set on this page, one to the reviewers table with a blank redirect already, then the one to the reviews table. Is it best to scrap these existing insert behaviours and start again?

Dave Buchholz
07-21-2010, 02:31 AM
You are using the standard DW Insert Server Behaviours at the moment, not the DataAssist ones. Does that help ?

jeffmg279672
07-21-2010, 02:39 AM
Yes, I see that, and have removed the standard insert behaviours and tried replacing with the DA insert behaviour - I've obviously done something wrong though as I'm now getting an error message: "Column 'practice_id' cannot be null" when I click submit on the first page, so I've obviously screwed something up somewhere.

Dave Buchholz
07-21-2010, 03:17 AM
Post your new files and let's have a look see what the issue is

jeffmg279672
07-21-2010, 03:24 AM
Attached, thanks.

Dave Buchholz
07-21-2010, 03:33 AM
Your problem is that you are trying to use recordsets and these will have no value as the data has not yet been inserted into the database.

I have corrected the inserts to use the form values, see attached.

jeffmg279672
07-21-2010, 03:42 AM
Dave - thanks for that. I haven't made any changes to the first page (review_add.php) but when I select the location then select the practicename when testing locally and hit submit, I get the add_review.php page coming up with the message:

Column 'practice_id' cannot be null

Not sure why this is happening.

Dave Buchholz
07-21-2010, 03:47 AM
Rename the submit button in review_add.php e.g.

<input type="submit" name="SubmitNow" value="Submit" />


Both pages have the submit button named identically and it is easier change this one as the database inserts rely on the button name in add_review.php

jeffmg279672
07-21-2010, 04:27 AM
Working perfectly, thanks. Can I really push my luck and ask a DA-related question? I had a search/results page working which doesn't function properly now as I had to remove the locations column from one table and use it to create a new table, so I need to make a selection based on the locations table and then display the results from the practicelist table and am not sure how to set about this.

Dave Buchholz
07-21-2010, 04:46 AM
1. Create a recordset that pulls every single row of information that contains the data you require

2. Create a form that has the elements you need to filter on (if this has dropdowns create the necessary recordsets for these as well)

3. Use the Data Assist Search Wizard to create the magic for you.

jeffmg279672
07-21-2010, 06:41 AM
Thanks for that - I realise that I referred to a search/results page where I should have said a search page and a results page sorry, a basic error.
The search page pulls a dynamic list from the locations table and this should then display on the following (results) page data from the practicelist table, so I'm assuming that I'll need something like a session variable (location_id from the locations table?) to pass to the 2nd page so that it matches the data to be displayed with the correct location (if that even makes sense). Which presumably means two recordsets - one for locations on the first page, one for practicelist for practice info on the second page.

Dave Buchholz
07-21-2010, 06:58 AM
the basic premise is the same whether the search form and results are on the same page or not

set up your initial (search) page with the form elements (plus recordsets) that you need and then the results page with the recordset that will display the data

from within the wizard you can choose which form you want to use to filter the recordset on the results page

jeffmg279672
07-21-2010, 08:14 AM
I've set up these two pages with form elements and recordsets as suggested, but when I run the DA search wizard all it's doing is let me set up the search page - no options to set a results page and nowhere that I can see where I can choose the form to filter the recordset on the results page.
Really not getting this at all...

Dave Buchholz
07-21-2010, 08:20 AM
are you using the correct wizard ?

the 2nd screen allows you to choose your search page

jeffmg279672
07-21-2010, 08:31 AM
that's the one I'm using: Insert>WebAssist>DataAssist>DataAssist Search Wizard. I don't have a problem with the selection of the search page, it's just that following the rest of the wizard through doesn't seem to provide a screen where I can select what I want on the results page - and in fact I need to link from the name of the practice on the results page to a detail page.
I have this working on a live site at:
http://www.clarewebhosting3.co.uk/goodvetguide/practice_Search.php

the only issue is that since the database was split, the locations data is now in a separate table, which is why I thought it might just be a matter of tweaking the existing 3 pages so that a session variable (or whatever) would be passed from the first page to the results page and so on.

I've used the DA Search Wizard before, but have always worked with a single db table where there's no room for confusion, but this relational stuff has really got me on the ropes - at the moment I can't see how I'm supposed to link some of these elements together to make it all talk to itself in the right way.

Dave Buchholz
07-21-2010, 08:40 AM
Whether the data is is one or more tables should make no difference as you are filtering the form post against the recordset values.

I see you are based in the UK, why don't you contact me (my details are in my signature) I do a lot of subcontracting for other developers.

jeffmg279672
07-21-2010, 10:34 AM
Dave - thanks for all your help, finally got the DA Search Wizard sorted and working.

Dave Buchholz
07-21-2010, 10:36 AM
excellent, good luck with the rest of the project