Open Source & Stuff  
  |     Main Site     |      Forum     |     Contact     |
Ajax Linked Select boxes :  forum.Salix.gr forum.Salix.gr
Comments, questions, usage, bugs. 
Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
message3 Linked Select Boxes from 2 Tables
Posted by: rtracey (IP Logged)
Date: January 14, 2008 11:07PM

This is a great download! It's been quite an adventure trying to link the results from 3 select boxes and I this is by far the simplest solution I've found. Thanks for your work!

Anyway, I am creating a page that requires 3 different linked select statements. The user first needs to select a volume, then an issue, and then a section. Both the volume and issue come from one table, "issues," which has an entry for every issue. Among other data, each entry has an issue number ('issue'), volume number ('vol'), and primary key ('id'). There is then a separate table with entries for each section, which includes a field called 'issueid', which corresponds to the primary key 'id' in the issues table. It also includes a 'name', which is what i want to be displayed to the user, and an 'id', which is what i want the value ultimately submitted by the form to correspond to.

Below is the code i have written so far. All of the select boxes work when they are not linked (except their results are not filtered). When they are linked, I can select the Volume, but data for the other two fields does not show-up. Please forgive me if this is a dumb question to submit, I'm a beginner at using php classes and AJAX stuff.

<?php
include("top_script_ArticleLux.php");
include("sc_classes.php");

$sc_ajax_select_boxes = new sc_ajax_select_boxes();
$sc_ajax_select_boxes->add_select_box('issues','vol','vol','','','newVolume','sel_id_1','');
$sc_ajax_select_boxes->add_select_box('issues','id','issue','','','newIssue','sel_id_2','');
$sc_ajax_select_boxes->add_select_box('sections','id','name','','','newSection','sel_id_3','');
$sc_ajax_select_boxes->link_select_boxes('newVolume','newIssue','vol','');
$sc_ajax_select_boxes->link_select_boxes('newIssue','newSection','issueid','');
$sc_ajax_select_boxes->place_jscripts();
?>
Volume:
<?php $sc_ajax_select_boxes->show_select_box('newVolume');?>
&nbsp;Issue:
<?php $sc_ajax_select_boxes->show_select_box('newIssue');?>
&nbsp;Section: <?php $sc_ajax_select_boxes->show_select_box('newSection');?>
<input name="articleid" type="hidden" id="articleid" value="<?php echo"$articleID";?>" />
<input name="sectionid" type="hidden" id="sectionid" value="<?php echo"$sectionID";?>" />
<input name="vol" type="hidden" id="vol" value="<?php echo"$vol";?>" />
<input name="issue" type="hidden" id="issue" value="<?php echo"$iss";?>" />



Thank you!!!

messageRe: 3 Linked Select Boxes from 2 Tables
Posted by: panos (IP Logged)
Date: January 24, 2008 09:22AM

First of all, sorry for the late response.

Now about your case. I see an issue with your issues smiling smiley
In issues table. Each issue has the Vol so Vols are not unique in that table. This gives a
problem because you will have an option for each issue and not for each volume.
That can be solved with a DISTINCT in the select statement, but there is not in the code.
You can tweak code a little, file sc_classes around line 288 you will find a line like
$cmd = "SELECT $key_fld, $text_fld FROM $table ";
making it like
$cmd = "SELECT DISTINCT $key_fld, $text_fld FROM $table ";
should do the trick.

Solving that, then we have to deal with the ajax issue, pls have a look at
[forum.salix.gr] there are lots of debuging tips there.
Maybe i should put that info in a more findable place smiling smiley
If nothing works, hit me again. Always happy to help.

Best Regards
Panos



Sorry, only registered users may post in this forum.

All Rights Reserved 2006 Salix.gr  |  Design by Ades Design |  Hosting by e-emporio |  forum.Salix.gr powered by Phorum