Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Select field that pulls data from another table

Quote Reply
Select field that pulls data from another table
How can I add a field to the Links table that presents the user with a select box (dropdown). In this dropdown I would like the results of a SELECT query on another table (named "Venues").

Is this possible?


Quote Reply
Re: Select field that pulls data from another table In reply to
take a look at how db_gen_category (or whatever it's called now) works. You can follow it backwards from the add.cgi program.

In short, you need to make a select call for the field you want from the table you want tablename.fieldname, then put the results into a drop-down box "token" and include that on your form. Remember, a select box has two parameters, the visible name, and the passed back value, so you need to set both appropriately.

PUGDOG® Enterprises, Inc.
Quote Reply
Re: Select field that pulls data from another table In reply to
I did this in Links v.1.3 using a foreach loop of records found in the query...(basically what pugdog alluded to), but I made the select codes into a template file using tags from the table....

Like the following:


<select name="ColumnName" size="1">
<option value="<%columname%>"><%columntitle%></option>

Basically, this template is pulled if the query finds records....

In the main template:


<%if Columname%>
No Records Found.

Basically, I would recommend making the select field template based for easier management and flexibility.


Eliot Lee
Quote Reply
Re: [Heckler] Select field that pulls data from another table In reply to
I have added a 'select field' called Pais in LinksSQL 2.1 and when I add a tag in add.html I get this error:

Unknown Tag: 'Pais'

The field def is:

Position: 21
Column Name: Pais
Column Type: ENUM(Seleccione un País, Albania, Alemania, Andorra, Arabia Saudi, Argentina, Australia, Belice, Belorusia, Bolivia, Brasil, Bélgica, Canada, Chile, China, Colombia, Costa Rica, Cuba, Dinamarca, Ecuador, Egipto, El Salvador, España, Estonia, Filipinas, Finlandia, Francia, Grecia, Guatemala, Honduras, Holanda, Hungría, Indonesia, Inglaterra, Islandia, Israel, Italia, Japón, Kenia, Korea, Lativia, Libia, Lichestein, Lituania, Luxemburgo, Marruecos, Mozambique, México, Nicaragua, Noruega, Nueva Zelanda, Panamá, Paraguay, Perú, Polonia, Portugal, Puerto Rico, Rep. del Congo, Rep. Dominicana, Rumania, Rusia, Serbia, Singapur, Slovakia, Slovenia, Suecia, Suiza, Sudáfrica, Trin. y Tobago, Tunez, Turquia, USA, Ucrania, Uruguay, Venezuela)
Not Null: Yes
Default: Selecione un País
Form Display: Pais
Form Type: SELECT

Need I to make other changes?

Thanks in advance!