Page 1 of 1

Line Code Issues

Posted: Fri Apr 27, 2007 12:40 pm
by NuclearDoctor
Im having a problem when I did my php code, the code that is at 'select member' will work for my first drop down box. Then I have another box thats just like that but its a line down and I have the same code for 'select member' but when I save the file, the first 'select memebr' will work but the second won't load the peoples names, it just stays as 'select member' but when i click on the first drop down box, everyones name is there, can someone help me out? Thanks

Code: Select all

<?

include "connect.phtml";
$db=delranfire_org;
if(isset($_POST['select'])){ 


}//end if 
$query="select name from member order by name asc";
$rows=mysql_db_query($db,$query,$connection) or die("Error in query:$query. " .mysql_error());

?>
<html>
<head>
<title>
<?
include "admin_panel_title.php";?>
</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#FF3333" vlink="#CC0000" alink="#CC0000">
<form action="231officers.phtml" method="post">
<center>
<img src="/newadmin/Administration_Panel_Banner.png"><br>
<h3>Station 231 Officers</h3>
  <table border="1" cellspacing="0" cellpadding="0" align="center">
    <tr>
      <td colspan="2">
         <center>
            <I>Line Officers</I>
         </center>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Deputy Chief (2310):&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>
        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Captain (2301):&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>
        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>1st Lieutenant (2303):&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>
        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>2nd Lieutenant (2305):&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>
        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Chief Engineer:&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>
        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Asst. Engineers (5):&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select><br>
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select><br>
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select><br>
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select><br>
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Fire Police Captain:&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Fire Police Lieutenant:&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
      </td>
    </tr>
    <tr>
      <td colspan="2">
         <center>
            <I>Administrative Officers</I>
         </center>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>President:&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Vice President:&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Treasurer:&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Financial Secretary:&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Corresponding Secretary:&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Trustees (3):&nbsp</b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select><br>
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select><br>
        &nbsp<select name="select">
          <option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
      </td>
    </tr>
    <tr>
      <td colspan="3">
        <div align="center">
          <input type="submit" name="Submit" value="Update">
          <input type="reset" name="reset" value="Clear Information">
        </div>
      </td>
    </tr>
  </table>
  </form>
<a href="/newadmin/">Back to Administration Panel</a>
</body></html>
  <?
  mysql_close();
  ?>
^^ Full page code

Code: Select all

<option>Select Member</option>
          <?
          while($row=mysql_fetch_array($rows))
          {
          echo "<option value='$row[name]'>$row[name]</option>";
          }
           ?>        </select>
^^Select Member code

Posted: Fri Apr 27, 2007 1:07 pm
by John Cartwright
You will have to change the pointer back to the first line, using mysql_data_seek()

However, my advise would be to loop the result set once, and store the results into an array

Code: Select all

$names = array();
while($row=mysql_fetch_array($rows))
{
   $names[] = $row['name'];
}
And then use a foreach() to traverse the array whenever you need to create a dropdown.

Posted: Fri Apr 27, 2007 1:36 pm
by NuclearDoctor
Jcart wrote:You will have to change the pointer back to the first line, using mysql_data_seek()

However, my advise would be to loop the result set once, and store the results into an array

Code: Select all

$names = array();
while($row=mysql_fetch_array($rows))
{
   $names[] = $row['name'];
}
And then use a foreach() to traverse the array whenever you need to create a dropdown.
What do you mean, im lost... sorry

Posted: Fri Apr 27, 2007 2:02 pm
by John Cartwright
What part are you lost on?

Posted: Fri Apr 27, 2007 2:09 pm
by onion2k
This looks wrong to me:

Code: Select all

$db=delranfire_org;

Posted: Fri Apr 27, 2007 2:12 pm
by NuclearDoctor
onion2k wrote:This looks wrong to me:

Code: Select all

$db=delranfire_org;
No, thats right, the database does connect and the members names load, except it only loads for the one drop down box, the very first one, the rest of them, nothing loads.. so if the one does load then it is connecting to the database