0

hya im trying to populate a drop down select list from the database i have set the database up and written the following out if anyone can help would be much appreicated

// Fetch user details
$userdata       = mysql_query("select * from user where user_id = '".$_SESSION['userid']."' ");
$fetch_user     = mysql_fetch_array($userdata);
$user_country   = $fetch_user['user_country'];
$user_towns = $fetch_towns['user_towns'];

$userinfo       = mysql_query("select * from user_info where user_id = '".$fetch_user['user_id']."' ");
$fetch_info     = mysql_fetch_array($userinfo);
$fetch_towns            = mysql_query("select * from towns where town_id = '".$fetch_towns['town_id']."' "); ITS THIS LINE TO QUERY

The following is the but to populate from

<?php
                    $towns = mysql_query("select * from towns where town_id = '".$user_town."' order by name asc");
                ?>
                  <select name="town" id="town" class="list_drop">
                    <option value="" selected="selected">Select</option>
                    <?php while($row = mysql_fetch_array($state)) { ?>
                    <option value="<?php echo $row['name']?>" <?php if($fetch_towns['town']==stripslashes($row['name'])) echo "selected";?> >
                    <?php echo $row['name']?>
                    </option>
                    <?php } ?>
                  </select>

Heres database table missing the inserted data

CREATE TABLE IF NOT EXISTS `towns` (
  `town_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `town` varchar(50) NOT NULL,
  PRIMARY KEY (`town_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=993 ;
2
Contributors
3
Replies
26
Views
2 Years
Discussion Span
Last Post by lps
0

Your code should populate correctly, Just that I saw this line while($row = mysql_fetch_array($state)) where $state is probably not defined.

0

First of all, the functions of mysql_* is depreciated, please use mysqli or pdo. Then, through your code, you assign the result of sql into $towns = mysql_query("select * from towns where town_id = '".$user_town."' order by name asc"); therefore, the code for while($row = mysql_fetch_array($state)) should be changed to $town of your database result.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.