I'm creating a function to help me return 1-M (One to Many relationship) results from my database.
What I want to achieve:
I have a form with a Location dropdown.
I want a function that will take the Column name (in this case "Location") and The Table name of the Table that I want to STORE the results in. Then reverse lookup the Column's.
<select>
<option value="1">London</option>
<option value="2">Somewhere else</option>
<?
$array=DataLink("location","form1");
php foreach($array as $row){
echo "<option value=\"".$row[0]."\">".$row[1]."</option>";
}
?>
</select>
My Database would look like this:
|Form1 | |Locations |
--------------------------- -------------------------------
|Name | |ID |
|Location | |CityName |
|OtherInfo | -------------------------------
---------------------------
Now I can see that the easy solution would be to simply use the Column name to relate to the specific Table that holds the info for that column. But I don't want to do that. I'm wanting to use a "Foreign Key" of sorts, or some other method to find the relationship between a column and it's 1-M link...
Can anyone tell me how they would approach this. Is there a way to link tables together like this so that we can see the relationship between the data etc?
Thanks in advance to any and all who contribute to this.
---EDIT--- As a side note, since this seemed to raise issue with programming standards. I'm working on a system where several people are developing several different modules etc. My tables are all prefixed with my uniqueID (24) so my table Form1 is actually 24_Form1 and Location is actually 24_Locations. If someone were to want to use my Locations list for themselves, they would simply link their xx_FormY to my 24_locations, and be able to use the same function to pull the appropriate info. It's better than me naming every column in my table 24_xxxx, and forcing them to do the same. Thanks