|
Posted by Kentor on 12/19/06 13:42
J.O. Aho wrote:
> Kentor wrote:
> > Hello, I'm in the following situation.. and i was wondering if anybody
> > had any idea on how to solve this problem:
> > I run a website for people to search/post apartments and vacation
> > rentals... I'm hoping to make my website worldwide as soon as possible
> > but adding new areas requires a really long time and making changes to
> > any of these areas is a real pain as well... I guess I chose the wrong
> > way to do it when I started and I really need to come to a solution if
> > I want things to go faster... The thing is, I have a bunch of switches
> > all over the website in a few files... about 15 files in total... so
> > everytime I add a new area, i need to modify 15 files... I would have
> > created one file and then just included it in all of those but the
> > switches are all different...
>
> Seems you missed the include() function
> http://www.php.net/manual/en/function.include.php
>
I can't include them because they are all different altho similar.... I
can't include the area alone because there's code after and before the
area that is different in each part. Take a look at the examples I
gave...
> If you have the same code in many places you just make an include file (I do
> suggest you let the file end on a .php, as otherwise the code may be readable
> for web users).
>
> Another and I think in your case better, is to use a database table
>
> table TheAreas
> AreaID INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
> AreaName VARCHAR(40) NOT NULL
>
> with a simple while loop you can query the table and create your area drop
> down menu
>
> function makeAreaMenu() {
> $query="SELECT AreaID,AreaName FROM TheAreas";
> $result=@mysql_query($query);
> if(!$result) {
> return;
> }
> $string= "<select name=\"Area\">\n<option>Select Area</option>\n";
> while($row=mysql_fetch_array($result)) {
> $string.= " <option value=\"{$row['AreaID']}\">{$row['AreaName']}</option>\n";
> }
> $string.= "</select>\n";
> return $string;
> }
>
> each time you want to create the drop down menu, then include the file where
> you stored the function and then call the function:
>
> include_once('areamenu.inc.php');
> makeAreaMenu();
>
> and you have it
>
> if you want the name for an area, then you just make a simple query again
>
> $query="SELECT AreaName WHERE AreaID='$usersubmittedvalue'";
> $result=@mysql_query($query);
> $data=mysql_fetch_array($result);
> echo $data['AreaName'];
>
> Of course if you want to use a load of checkboxes, it works too, just modify
> the code somewhat, but I hope you got some idea how to do things.
>
I thought about using a database... but wouldn't this create waaaay too
much DB interaction for nothing... I mean each time any user on the
website needs to use the list they would query the db... that will be a
LOT of querys per day... or even per minute... and as the website grows
it will be too many per second.. no?
>
> --
>
> //Aho
[Back to original message]
|