Jump to content


Photo

Filter Data


  • Please log in to reply
4 replies to this topic

#1 nestorvaldez

nestorvaldez
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 September 2006 - 04:05 PM

I need some Help.
I want to filter my data in two combo box field, retreiving the data form my mysql DB.
Ex.
I have three DB : country, city, customer; city is relationed with country; and customer with both
so I want that when I select on country in the Customer Form the script could show/filter only the cities that belong to this country..

COUNTRY         
- id
-countryname

CITY         
- id
- cityname
- country

CUSTUMER
- id
- name
- country
- city
                 

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 September 2006 - 04:14 PM

city and country is in customer why not echo the city form that table.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 20 September 2006 - 04:15 PM

ok. so if the country table has an ide and city has an aread for the country, then ur set.

Simply call the city by country:
// let's just say the country id is 2 //
$country_id = 2;
$sql = "SELECT * FROM CITY WHERE country='" . $cid . "'";
$results = mysql_query($sql);

while($row = mysql_fetch_rows($results)){

 // HERES UR CITIES

}



#4 nestorvaldez

nestorvaldez
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 September 2006 - 07:32 PM

Im getting problem doing it..
The problem is, it is in the new record form Im try to register a new one.. So I dont have it the code in the DB, yet.. My problem is that I cant make refresh the page in order show the city in my combo, depending on the country I selected.. I mean the first field is the country and the next one is the City, then I want that when I select the One country and go out from this field to the next it make the refresh or what ever and show me in the next field (the Cities combo) just the cities from the country I selected...

This is my code to select the country from the DB

<select size="1" name="country"  tabindex="13">
  <?php
          $query = mysql_query("SELECT PAI_ID, PAI_NOMBRE FROM pais");
    while ($row = mysql_fetch_array($query)) {
    $pid=$row['PAI_ID'];
    $pnombre=$row['PAI_NOMBRE'];
    ?>
    <option value="<?=$pid?>" <?//=$selected?>><?=$pnombre?></option>
    <?
    }
    ?>
</select>


and this is to select the City:

  <select size="1" name="city" tabindex="12">
  <?php
          $query = mysql_query("SELECT CIU_ID, CIU_NOMBRE FROM ciudad" WHERE CIU_PAIS=$pid);
    while ($row = mysql_fetch_array($query)) {
    $cid=$row['CIU_ID'];
    $cnombre=$row['CIU_NOMBRE'];
    ?>
    <option value="<?=$cid?>" <?//=$selected?>><?=$cnombre?></option>
    <?
    }
    ?>
</select>

How to refresh dinamically when the focus leave the Country field

#5 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 20 September 2006 - 09:42 PM

well you have a problem with your code i noticed immediatly.. this:
<option value="<?=$pid?>" <?//=$selected?>><?=$pnombre?></option>

should be more like this:
<option value="<? echo $pid; ?>" <? echo $selected; ?><? echo $pnombre; ?></option>

and you can refresh using javascript. I'm not real good with javascript but a search on google should come up with good results.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users