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
messageSelecting 3 database columns
Posted by: gcan (IP Logged)
Date: November 20, 2008 05:52PM

Hello,

I guesss it's not possible, but decided to ask anyway.

Is it possible to select 3 database columns so that results looks like this?

<option value="$value1">$value2 ($value3)</option>

Thank you very much.

messageRe: Selecting 3 database columns
Posted by: panos (IP Logged)
Date: November 21, 2008 08:22AM

Hi,
if you are working on a server with mysql 5 you can create a view and make there the description column look the way you need and use the view for the linked select boxes.

Best regards
Panos

messageRe: Selecting 3 database columns
Posted by: gcan (IP Logged)
Date: November 21, 2008 10:45AM

No, it's not Mysql 5 sad smiley

messageRe: Selecting 3 database columns
Posted by: gcan (IP Logged)
Date: November 22, 2008 09:23AM

I tried to customize the script, but got lost... So many functions...

If somebody can do it for me, I can pay some money.

It's necessary to add one more SELECT field to:

$sc_ajax_select_boxes->add_select_box('islands','id','name','id','','island','island_id','','',$text1,$additional_select_field);

so that result look like this:

<option value="$id">$name ($additional_select_field_value)</option>

messageRe: Selecting 3 database columns
Posted by: panos (IP Logged)
Date: November 24, 2008 02:22AM

Goodmorning,

I just had an idea!

can you please give a try the following?

$sc_ajax_select_boxes->add_select_box('islands','id','name','id','',
"concat(island,' (',some_filed,')')",
'island_id','','',$text1,$additional_select_field);

I am prety sure that the code want mind (not using assosiative array to retrieve records from db).

messageRe: Selecting 3 database columns
Posted by: gcan (IP Logged)
Date: November 24, 2008 05:26AM

Hello Panos,

Thank you very much for yout reply.
Your suggestion works, but... only with first select box (islands) - it shows both retrieved records. When I add "concat" to Municipalities and Cities, the script stops working - second select box stays dead and doesn't show any municipalities list when I change "island" in the first select box.

This is my script. Everything looks correct, but the script doesn't like something.

$sc_ajax_select_boxes->add_select_box('islands','id',"concat(name,' (',total_number,')')",'id','','f_island','island_id','','',$text1);
$sc_ajax_select_boxes->add_select_box('municipalities','id',"concat(name,' (',total_number,')')",'name','','f_municipality','municipality_id','','',$text1);
$sc_ajax_select_boxes->add_select_box('cities','id',"concat(name,' (',total_number,')')",'name','','f_city','city_id','','',$text1);

messageRe: Selecting 3 database columns
Posted by: panos (IP Logged)
Date: November 25, 2008 08:15AM

found it!
pls edit file sc_classes.php around line 540 there is line:

echo " pars += '&text=".$this->select_boxes[$link_props['child']]['text_field']."';"."\n";

edit to:

echo " pars += \"&text=".$this->select_boxes[$link_props['child']]['text_field']."\";"."\n";

and it should work. Atleast it does for me.

Best regards
Panos

messageRe: Selecting 3 database columns
Posted by: gcan (IP Logged)
Date: November 25, 2008 10:29AM

Hello,

Thank you, panos. I changed that line in sc_classes.php.

Now there is another problem. First box displays everything correct. On second and third box it works only when I remove any additional characters (brackets) from "concat".

If I use:
"concat(name,' (',total_number,')')"
select box refreshes, but doesn't return any results. It returns "None".

It works only if I use
"concat(name,total_number)"

But I need al least space between both records. I tried to replace brackets with "-" or empty space - it doesn't return any records anyway.

How you tested it with brackets or any other characters between both selects?

Thanks.

messageRe: Selecting 3 database columns
Posted by: panos (IP Logged)
Date: November 26, 2008 02:21AM

well, my actual test code is

$sc_ajax_select_boxes->add_select_box('sc_page_types','page_type',"concat(page_type,' - ',type_descr)",'page_type','','sel1','sel_id_1','');
$sc_ajax_select_boxes->add_select_box('sc_page_types_sub','sub_type',"concat(sub_type,' - ',type_descr)",'sub_type','st21','sel2','sel_id_2','');

$sc_ajax_select_boxes->add_select_box('sc_page_types_sub_sub','sub_type',"concat('(',sub_type,') ',type_descr)",'sub_type','st22','sel3','sel_id_3','');

$sc_ajax_select_boxes->add_select_box('sc_page_types_sub_sub','sub_type',"concat(sub_type,' - ',type_descr)",'sub_type','st22','sel4','sel_id_4','');

messageRe: Selecting 3 database columns
Posted by: panos (IP Logged)
Date: November 26, 2008 02:30AM

just to make sure download this version of sc_classes [salix.gr]

messageRe: Selecting 3 database columns
Posted by: gcan (IP Logged)
Date: November 26, 2008 05:06AM

Hello Panos,

The version of sc_classes is corect, but it's not working anyway.
To check if MySQL query is correct, I added:

echo "$cmd";

to the functions in sc_classes.php file. Php echo shows the following:

First box which is working ok:
SELECT id, concat(name,' - ',total_number) FROM islands ORDER BY id

Second box which returns "None" result:
SELECT id, concat(name,\' - \',total_number) FROM municipalities WHERE island= '2' ORDER BY name

As you can see, second query contains backslashes \' - \', but first query does not. I think this causes "none" result, but can not underastand yet why second query contains backslashes.

messageRe: Selecting 3 database columns
Posted by: panos (IP Logged)
Date: November 26, 2008 10:14AM

Hi,
this is strange!
looks like parameter is escaped...
pls check your server setting magic_quotes_gpc if is on or off
that parameter is send via post to the server when you select in the first select box.

messageRe: Selecting 3 database columns
Posted by: gcan (IP Logged)
Date: November 27, 2008 04:16AM

magic_quotes_gpc is on

messageRe: Selecting 3 database columns
Posted by: panos (IP Logged)
Date: November 28, 2008 02:56AM

ok,
download this one [salix.gr] i urlencoded that parameter hopping that the server will not escape it.
Changes made in sc_classes.php line 540

echo " pars += \"&text=".urlencode($this->select_boxes[$link_props['child']]['text_field'])."\";"."\n";

and file sc_select_ajax_handler.php line 54

$text = urldecode($_REQUEST['text']);

pls give it a try

messageRe: Selecting 3 database columns
Posted by: gcan (IP Logged)
Date: November 28, 2008 06:45AM

Hello Panos,

I downloaded the changed script, but it doesn't work anyway. But I resolved the problem by adding this line to sc_select_ajax_handler.php file

$text = stripslashes($_REQUEST['text']);

Now everything works fine. The only thing what I can not understand is why backslashes are added only to the second box, but the first one works fine without "stripslashes".

Thank you for your help.

messageRe: Selecting 3 database columns
Posted by: panos (IP Logged)
Date: November 28, 2008 08:23AM

The first one is populated server side at page creation (basicly all off the if there is a selected value).
When you select value on first one then a request is send via ajax and there slash are added.



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