Jump to content

[SOLVED] I am not sure why this is not working....


karatekid36

Recommended Posts

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');
?>

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();
  }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.