Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Select Fields

Quote Reply
Select Fields
Hi,
Does anyone have the code needed to build a select field based on the data from another table? I know this can be done with the standard DBMan but how do I do it with DBMan SQL?
Thank you.
Simon.

Quote Reply
Re: Select Fields In reply to
Hi Jai,
Well this is the first time Ive ever been able to help anyone out, hope this works it did for me.

First in you cfg file add
$db_table_reqfield (call it whatever you want really)

Then in the the db.cgi copy and paste this sub
sub build_select_field_from_db

and rename it build_select_field_from_reqfield (or once again what ever you want to call it)

then in the new sub replace this line
SELECT DISTINCT $column FROM $db_table

with
SELECT DISTINCT $column FROM $db_table_reqfield (the same as you called it in the cfg file)

The last thing to do is add the info into the html file where you want to use it.

e.g
print &build_select_field_from_reqfield("reqfield",$rec{'reqfield'})

(call it the same as you did in the db.cgi file)
Hope that works for you.

Cheers
Zero73
Sydney, Australia



Quote Reply
Re: Select Fields In reply to
Hi zero73,
Thank you for your reply.
This forum is not very active so your reply was a nice surprise.
I took you explanation a step further and added the red parts below.
It worked fine so I guess what I did was correct.

>>>Your Explanation<<<<
First in you cfg file add
$db_table_reqfield (call it whatever you want really)

Then in the the db.cgi copy and paste this sub
sub build_select_field_from_db

and rename it build_select_field_from_reqfield (or once again what ever you want to call it)

then in the new sub replace this line
SELECT DISTINCT $column FROM $db_table

with
SELECT DISTINCT $column FROM $db_table_reqfield (the same as you called it in the cfg file)

The last thing to do is add the info into the html file where you want to use it.

e.g
print &build_select_field_from_reqfield("reqfield",$rec{'reqfield'})
(call it the same as you did in the db.cgi file)


>>>New Explanation<<<
First in you cfg file add

$db_table_reqfield='table_name'; (call it whatever you want really)
Then in the the db.cgi copy and paste this sub
sub build_select_field_from_db

and rename it build_select_field_from_reqfield (or once again what ever you want to call it)

then in the new sub replace this line
SELECT DISTINCT $column FROM $db_table

with
SELECT DISTINCT $column FROM $db_table_reqfield (the same as you called it in the cfg file) add a WHERE if needed.

The last thing to do is add the info into the html file where you want to use it.

e.g
print &build_select_field_from_reqfield("column_name",$rec{'column_name'})
(call it the same as you did in the db.cgi file)

How does that look??
If I want to build tables from multiple tables do I need a new subroutine for each one???
Thanks again for your help.
Simon.