You are here: Re: about structure. « All PHP « IT news, forums, messages
Re: about structure.

Posted by J.O. Aho on 12/19/06 13:28

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

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.


--

//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация