Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Adding new field

Quote Reply
Adding new field
Hi,

I'm trying to add new field and also add it in the form for adding new links.

The filed is countryid , I added a column in Links table.

Now i'm stuck with the form. I want the form to show a select filed with the countries. How can I do this?
Quote Reply
Re: [Essam] Adding new field In reply to
Don't want to complicate things, but I think that there is a flaw in your DB schema. Why are you limiting links to only one country relation? This may be highly restrictive for your users. What if a resource or link can be associated with multiple countries?

Example:

Someone has created a web site about Madagascar, and wants to add the resource/link to "Africa" and "Madagascar".

Right now you have a 1->M relation between Links and Countries (one country can be associated with MANY links, but not vica versa).

I would suggest creating an intersection table called something like Links_County_Links:

LinkID (Index, NOT UNIQUE - MAL)
CountryID (Index, NOT UNIQUE - MAL)

Then in your add routine, you would use the following INSERT query:

INSERT INTO Links_Country_Links
(LinkID, CountryID)
SELECT $id, CountryID
FROM Links_Country
WHERE (CountryID IN ($IN->param('CountryID')))

or something like that (of course, converted with the Links SQL codes). Of course, adding conditional statements to see if the CountryID has been submitted in the add form.

For modifying/editing the link, you would use the following SQL Statements in your modify/edit routines:

DELETE FROM Links_County_Links
WHERE (LinkID = $linkid)

Then you can use the same INSERT statement above to insert the new country(ies) into the Links_Country_Links table.

$linkid is the variable used to identify the LinkID/record that is being edited.

As for creating the drop-down menu of Countries, you would have to create a global that would SELECT the countries from your COUNTRIES table. Example GLOBALS have been posted in this forum and also some are listed in the Gossamer Threads Resource section.

WORD OF ADVICE: It is best to create M<->M relations between tables (with adding intersection tables) to ensure future growth and flexibility.
========================================
Buh Bye!

Cheers,
Me

Last edited by:

Heckler: Apr 6, 2002, 10:29 PM
Quote Reply
Re: [Essam] Adding new field In reply to
>>Now i'm stuck with the form. I want the form to show a select filed with the countries. How can I do this? <<

You have to do it manually.
Quote Reply
Re: [Essam] Adding new field In reply to
You don't have to manually create the drop-down menu of Countries, as I mentioned you can create a global that would build a drop-down of Countries. You could copy the codes for building the Category drop-down and then change the table name to Countries. Or I believe that &build_select_field is still a sub in the recent versions of Links SQL.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] Adding new field In reply to
Yeah but is still a manual solution...ie Links SQL doesn't auto-generate it - you manually code something, whether it be a global or whatever :)

Last edited by:

Paul: Apr 7, 2002, 11:03 AM
Quote Reply
Re: [Heckler] Adding new field In reply to
Well, your response led me to believe that you manually create the drop-down menu in the add_form.html file.

Like:

<select name="CategoryID" size="1">
<option value="">Choose one of the following:</option>
<option value="1">SomeCountry</option>
<option value="2">SomeOtherCountry</option>
</select>

And that is not an appropriate solution since if you make changes in the Countries table, then you'd have to have continually edit the template file. Much better to CODE a global or plugin to "automatically" build a drop-down menu from the database directly.
========================================
Buh Bye!

Cheers,
Me