karatekid36 Posted May 2, 2007 Share Posted May 2, 2007 All I need to do is create this pulldown menu and have it load usernames from another table in the database. Any help would be greatly appreciated. Here is the code.... <?php require_once ('mysql_connect.php'); // Connect to the db. $page_title = 'Postions Held'; include ('includes/header.html'); ?> <h2>Postions Held</h2> <form action="pos_held.php" method="post"> <p><b>Brother</b> <select name="brother" ><option>Select One</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; $result = mysql_query($dbc, $query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$row['name']}</option>\n"; } mysql_close($dbc); ?> </select></p> </form> <?php include ('./includes/footer.html'); ?> Link to comment https://forums.phpfreaks.com/topic/49600-solved-i-am-not-sure-why-this-is-not-working/ Share on other sites More sharing options...
clown[NOR] Posted May 2, 2007 Share Posted May 2, 2007 shouldn't it be <?php echo '<select name="users">'; while ($row = mysq_fetch_array($result, MYSQL_ASSOC)) { echo '<option value="'.$row['user_id'].'">'.$row['name'].'</option>'; } ?> Link to comment https://forums.phpfreaks.com/topic/49600-solved-i-am-not-sure-why-this-is-not-working/#findComment-243196 Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Any help would be greatly appreciated. Here is the code.... And what is the problem? Link to comment https://forums.phpfreaks.com/topic/49600-solved-i-am-not-sure-why-this-is-not-working/#findComment-243201 Share on other sites More sharing options...
karatekid36 Posted May 2, 2007 Author Share Posted May 2, 2007 When I go to the pulldown menu, the list of users from the table I am pulling the information from is not there. That is the problem. Link to comment https://forums.phpfreaks.com/topic/49600-solved-i-am-not-sure-why-this-is-not-working/#findComment-243203 Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Well you fail to check your query succeeded before using it, maybe its failing. Try... <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> Link to comment https://forums.phpfreaks.com/topic/49600-solved-i-am-not-sure-why-this-is-not-working/#findComment-243217 Share on other sites More sharing options...
karatekid36 Posted May 2, 2007 Author Share Posted May 2, 2007 THANK YOU!!!!!!!!!! This is all fixed!!!!!! Link to comment https://forums.phpfreaks.com/topic/49600-solved-i-am-not-sure-why-this-is-not-working/#findComment-243221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.