GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Mar-2005, 13:31
robsmith robsmith is offline
New Member
 
Join Date: Mar 2005
Posts: 11
robsmith is on a distinguished road
Question

Please help! Select box problem!


Hi I am relatively new to php and am trying to create 2 list boxes- one listing countries and another listing regions within those countries. I am using a mysql database table (Villa) with the following fields:
villaID{PK}, villaName, location, region, price

(location contains the countries)

I am trying to create a form which lists the regions for a particular country once that country is selected. Here is the code so far:

PHP Code:

<?php 

//------------------------------------------------------------------------------------------------------------------------------------- 
function &SearchForm() 
{//Display the search form 

    $search = "<form id=\"SearchForm\" title=\"Avaliability Search\" action=\"index.php?page=pages/search.php\" method=\"post\">"; 
    $search .= "<br /><fieldset class=\"field\"><legend class=\"leyenda\"> Search </legend> <br />"; 
     
    //Country Label 
    $search .= "<label for=\"country\" title=\"Select the country\" class=\"indent\">*Country: </label>"; 

    //Query to list countries 
    $query = "SELECT location, region FROM Villa ORDER BY location"; //Make the query to show all countries' names in alphabetical order. 
    $result = @mysql_query($query); //Run the query. 
    if ($result) //If it ran ok, display the records. 
    { 
        if (mysql_num_rows($result) > 0) 
        { 
    //Select box 
    $search .= "<select id=\"location\" name=\"location\" title=\"Select Country\" class=\"inputframe\">"; 
        while ($row = mysql_fetch_array($result)) 
    { 
    if (isset($_POST['location']) && (strcmp(stripslashes($row[0]), $_POST['location']) == 0)) 
    $search .=  "<option selected=\"selected\">"; 
    else 
    $search .= "<option>"; 
    $search .= stripslashes($row[0])."</option>"; 
    } 
    mysql_free_result($result); //Free up the resources. 
         
    $search .= "</select> </p>"; 
     
    //Region     
    $search .= "<label for=\"region\" title=\"Region\" class=\"indent\">*Region: </label>"; 
    $search .= "<select id=\"region\" name=\"region\" title=\"Region\" class=\"inputframe\">"; 
    $search .= "</select> </p>"; 

    //Button 
    $search .= "<div class=\"centro\">"; 
    $search .= "<input title=\"Search\" class=\"submit\" id=\"formsent\" name=\"formsent\" type=\"submit\" value=\"Search\">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</button><br /><br /><br />"; 
    $search .= "</div></fieldset> </form>"; 
    } 
    else 
    $search .= "<p>There are currently no registered countries:</p>"; 
    } 
    else //If it did not run ok. 
    { 
        $search = "<p>The countries could not be displayed due to a system error. We apologise for any inconvenience.<p>"; 
        $search .= "<p>".mysql_error().": ".mysql_error()."</p>"; 
    } 
    return $search;             

} 
?>


I would be extremely grateful for any help/ advice,

Many thanks

Julie x x x
  #2  
Old 31-Mar-2005, 14:26
tycooner tycooner is offline
New Member
 
Join Date: Mar 2005
Location: Canada
Posts: 19
tycooner is on a distinguished road
Have it so that once you select a country, it resets the page, with the extension ?cnt=countryname. Then, create a new select box based on $_GET[''], and have that read the database WHERE location='{$_GET['cnt']}' and build that list.
  #3  
Old 01-Apr-2005, 02:59
robsmith robsmith is offline
New Member
 
Join Date: Mar 2005
Posts: 11
robsmith is on a distinguished road

re


ok thanks x
 
 

Recent GIDBlogA Week in Kuwait by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CD burner will not burn, new problem sdshaman Computer Hardware Forum 4 06-Feb-2008 23:17
Please help! Insert into database problem robsmith MySQL / PHP Forum 1 24-Apr-2005 03:44
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 07:53
select problem zuzupus MySQL / PHP Forum 0 15-Aug-2003 07:25
combo box select problem zuzupus MySQL / PHP Forum 2 23-Jul-2003 11:25

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:03.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.