rps1969 Posted February 12, 2009 Share Posted February 12, 2009 I am having a few issues, namely I wish to arrange the 'Location' dropdown box in my 'Submit Agent ' so it does not show alphabetically. I would prefer it to default to 'regionId' in the database tables under '_location' What I have done so far is in submit.php I have changed generate_options_list(LOCATIONS_TABLE, $form['realtor_location']) TO generate_options_list(LOCATIONS_TABLE, $form['realtor_location'],true) and then change includes/functions.php you have to add/change three lines line 1 changed function generate_options_list ( $name, $selected = '', $defaultorderby = false ) { global $db; global $cookie_language; if ($cookie_language == "english") $in = 'name'; if ($cookie_language == "french") $in = 'name2'; if ($cookie_language == "german") $in = 'name3'; if ($cookie_language == "italian") $in = 'name4'; if ($cookie_language == "russian") $in = 'name5'; if ($cookie_language == "spanish") $in = 'name6'; line 2 added $orderBy = ($defaultorderby != true) ? ' ORDER BY ' . $in : ''; //line 3 changed $sql = 'SELECT id, ' . $in . ' FROM ' . $name . $orderBy; $r = $db->query ($sql) or error ('Critical Error', mysql_error () ); $output = ''; while ($f = $db->fetcharray ($r) ) { if ($f['id'] == $selected) $output.= '<option value="'. $f['id'] . '" SELECTED>' . $f[1] . '</option>'; else $output.= '<option value="'. $f['id'] . '">' . $f[1] . '</option>'; } return $output; } However I have just added a new table where I link certain places (via their ID) to England/Scotland etc. So I add a relation to a region as follows CREATE TABLE IF NOT EXISTS `pmr_locations` ( `name` varchar(50) DEFAULT NULL, `name2` varchar(50) DEFAULT NULL, `name3` varchar(50) DEFAULT NULL, `name4` varchar(50) DEFAULT NULL, `name5` varchar(50) DEFAULT NULL, `name6` varchar(50) DEFAULT NULL, `id` int(5) unsigned NOT NULL AUTO_INCREMENT, `regionId` int null, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1503 ; create table if not exists region( regionId int not null, descr varchar(255) not null, primary key (regionId) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; insert into region(regionId, descr) values (1,'Wales'); insert into region(regionId, descr) values (2,'England'); insert into region(regionId, descr) values (3,'Scotland'); INSERT INTO `pmr_locations` (`name`, `name2`, `name3`, `name4`, `name5`, `name6`, `id`, regionId) VALUES ('Abbots Langley', NULL, NULL, NULL, NULL, NULL, 1, null), How will this change you last post and what changes will I need to make. Thanks for your continued help by the way. Link to comment https://forums.phpfreaks.com/topic/144968-default-to-regionid/ Share on other sites More sharing options...
Q695 Posted February 12, 2009 Share Posted February 12, 2009 If you're looking to build surveys, I run mine like this: $sql="SELECT * FROM criteria WHERE type='$type' AND rank<'10';"; $result=@mysql_query($sql,$con) or die(death($sql)); while ($row=mysql_fetch_array($result)){ ///////////////////////////////////////////////////////////////////////////// echo "<p><strong>".$row[value].":</strong><br>"; //////////////////////////////////////////////////////////////////////////// $sql2="SELECT * FROM criteria WHERE question='$row[question]' AND rank='10';"; $result2=@mysql_query($sql2,$con) or die(death($sql2)); while ($row2=mysql_fetch_array($result2)){ $style=$row['style']; switch ($style) { case 1: $field=" <br><input type='radio' name='$row[value]' value='$row2[value]'>$row2[value]"; break; case 2: $field=" <input type='text' name='$row[value]' >"; break; case 3: $field=" <input type='checkbox' name='$row[value]' value='$row2[value]'> $row2[value]"; break; case 4: $field=" <textarea name='$row[value]'></textarea>"; break; } echo $field; } echo "</p>"; } ?> Link to comment https://forums.phpfreaks.com/topic/144968-default-to-regionid/#findComment-760712 Share on other sites More sharing options...
rps1969 Posted February 12, 2009 Author Share Posted February 12, 2009 hI It's not to build surveys as such. It is simple drop down box where an agent will select what United Kingdom location they live in. I consider myself worse than hopeless when it comes to hard coding, but I suppose like many I have to start somewhere. Problem is just get to grips with it I then lose my way. Which is exactly what I did here, thus why I am asking for some help. What I have done is to create 2 mysql tables. 1 of them I just added `regionId`and to and another is a new regionId table as shown below values (1,'Wales');. Now I am stuck in trying to join it all up. I could pay someone to sort it out but how would that help me in learning? Link to comment https://forums.phpfreaks.com/topic/144968-default-to-regionid/#findComment-760753 Share on other sites More sharing options...
Q695 Posted February 13, 2009 Share Posted February 13, 2009 <select> <option value="Volvo">Volvo</option> <option value="Saab">Saab</option> <option value="Mercedes">Mercedes</option> <option value="Audi">Audi</option> </select> Link to comment https://forums.phpfreaks.com/topic/144968-default-to-regionid/#findComment-761069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.