Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dependent dropdown menu problem

Guest
Jul 30, 2009 Jul 30, 2009

I have 3 dependent dropdown menues setup in dreamweaver that gets their data from a MySQL Table.

When I use dreamweaver ot control the dropdown they work fine, but the data being fed into my db is the numeric value used to control the dropdown not the label. If I change the value of the dropdown in dreamweaver to the lable the dropdown arent dependent anymore.

I heard that I have to set Foreign Keys to fix this.

I would apreciate any help I can get.

My first table is province:

CREATE TABLE `db`.`province` (
  `id_prov` INTEGER UNSIGNED NOT NULL DEFAULT NULL AUTO_INCREMENT,
  `name_prov` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`id_prov`)
)
ENGINE = InnoDB;

Second is City:

CREATE TABLE `db`.`city` (
  `id_city` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `idprov_city` INTEGER UNSIGNED NOT NULL,
  `name_city` VARCHAR(65) NOT NULL,
  PRIMARY KEY (`id_city`)
)
ENGINE = InnoDB;

Third is Suburb:

CREATE TABLE `db`.`suburb` (
  `id_suburb` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `idprov_suburb` INTEGER UNSIGNED NOT NULL,
  `idcity_suburb` INTEGER UNSIGNED NOT NULL,
  `name_suburb` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`id_suburb`)
)
ENGINE = InnoDB;

TOPICS
Server side applications
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Aug 02, 2009 Aug 02, 2009

Province:

<option value="<?php echo $row_province['id_prov']?>"><?php echo $row_province['name_prov']?></option>

From the code above, you are storing the id_prov which i believe it was an integer type (value="<?php echo $row_province['id_prov']?>"). If you want to store the name_prov attribute, u should replace id_prov to name_prov.

But as u said, if u store the name_prov, the other drop down menu is not dependent anymore. It's true because from the city table, there is one attribute i guess was a

...
Translate
Guest
Jul 31, 2009 Jul 31, 2009

When u choose drop down menu, u may see that there are 2 important fields, values and label. The values field will store the value in database while the label field will only show the list to be chosen by users. What value that u want to store in databse?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 31, 2009 Jul 31, 2009

Here is the code.

I want to insert the lable into the database.

I am using the value to control the dropdown.

Province:

<tr>
      <td class="KT_th"><label for="province">Province:</label></td>
      <td><select name="province" id="province">
        <?php
do { 
?>
        <option value="<?php echo $row_province['id_prov']?>"><?php echo $row_province['name_prov']?></option>
        <?php
} while ($row_province = mysql_fetch_assoc($province));
  $rows = mysql_num_rows($province);
  if($rows > 0) {
      mysql_data_seek($province, 0);
      $row_province = mysql_fetch_assoc($province);
  }
?>
      </select>
        <?php echo $tNGs->displayFieldError("private_buyer", "province"); ?> </td>
    </tr>

City:

<tr>
      <td class="KT_th"><label for="city">City:</label></td>
      <td><select name="city" id="city" wdg:subtype="DependentDropdown" wdg:type="widget" wdg:recordset="city" wdg:displayfield="name_city" wdg:valuefield="id_city"  wdg:fkey="idprov_city" wdg:triggerobject="province" >
    </select>
          <?php echo $tNGs->displayFieldError("private_buyer", "city"); ?> </td>
    </tr>

Suburb:

<tr>
      <td class="KT_th"><label for="suburb">Suburb:</label></td>
      <td><select name="suburb" id="suburb" wdg:subtype="DependentDropdown" wdg:type="widget" wdg:recordset="suburb" wdg:displayfield="name_suburb" wdg:valuefield="name_suburb" wdg:fkey="idcity_suburb" wdg:triggerobject="city">
    </select>
          <?php echo $tNGs->displayFieldError("private_buyer", "suburb"); ?> </td>
    </tr>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 02, 2009 Aug 02, 2009

Province:

<option value="<?php echo $row_province['id_prov']?>"><?php echo $row_province['name_prov']?></option>

From the code above, you are storing the id_prov which i believe it was an integer type (value="<?php echo $row_province['id_prov']?>"). If you want to store the name_prov attribute, u should replace id_prov to name_prov.

But as u said, if u store the name_prov, the other drop down menu is not dependent anymore. It's true because from the city table, there is one attribute i guess was a foreign key (idprov_city) and u set it as int. That's why if u use id_prov(int), the dependent works fine.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 03, 2009 Aug 03, 2009

.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 03, 2009 Aug 03, 2009
LATEST

Hi

Thanks for your help.

I changed all the the values to varchars that corospond to the labels, and now uses them to control the dep drop down instread of the values, and it works.

Thanx.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines