V-Man Posted May 2, 2006 Share Posted May 2, 2006 Sure, it's been asked before, but I still don't get it. Can I get some help?[code]<?phpdefine('IN_MINVERA', TRUE);$type = $_GET['type'];include("includes/db.php");db_connect(); $sql = "SELECT title FROM articles WHERE type = $type";$result = mysql_query($sql) or die('Query failed. ' . mysql_error());if (mysql_num_rows($result) == 1) { while ($row = mysql_fetch_array($result)) { $title = $row['title']; ?> <select name=""> <?php echo("<option value='$title'>$title</option>"); ?> </select> <?php }} ?>[/code]Thats the code. When ?type=blablabla (happens to be om_article) I get the following error:Query failed. Unknown column 'om_article' in 'where clause'SQL table is set up as following:[code]CREATE TABLE `articles` ( `article_id` tinyint(10) unsigned NOT NULL auto_increment, `title` varchar(200) default '0', `type` varchar(200) default '0', `dop` varchar(20) default '0', `content` text, PRIMARY KEY (`article_id`)) TYPE=MyISAM AUTO_INCREMENT=29;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8858-populate-dropdowns/ Share on other sites More sharing options...
AndyB Posted May 2, 2006 Share Posted May 2, 2006 [code]<select name=""> [/code]That provides no method for passing the form variable anywhere. I suspect that what you want is:[code]<select name="title">[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8858-populate-dropdowns/#findComment-32496 Share on other sites More sharing options...
V-Man Posted May 2, 2006 Author Share Posted May 2, 2006 Nice spot, but thats just naming the HTML form element. With my current setup, I am not able to pass info into the select list to populate it because of my SQL. It's not finding something Im thinking... Ideas anybody? Quote Link to comment https://forums.phpfreaks.com/topic/8858-populate-dropdowns/#findComment-32498 Share on other sites More sharing options...
craygo Posted May 2, 2006 Share Posted May 2, 2006 first you should do is put single quotes around your strings in query[code]$sql = "SELECT title FROM articles WHERE type = '$type'";[/code]Second if you are populating a dropdown menu why would there be only one result from the query[code]if (mysql_num_rows($result) == 1)[/code]Should be[code]if (mysql_num_rows($result) > 0)[/code]Third your select tags need to be before the loop[code]echo "<select name=\"something\">"; while ($row = mysql_fetch_array($result)) { $title = $row['title']; print '<option value="'.$title.'">'.$title.'</option>;} echo "</select>";}[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/8858-populate-dropdowns/#findComment-32510 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.