Re: What am I doing wrong - PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stuart Felenstein wrote:

Ok, hopefully I can explain this clearly, even though
I think I might be an idiot since Ive been going on
about this for a few days.

I have a table that holds values and labels i.e. 1 = New York
2 = Boston
3 = Kansas City
4 = Amsterdam


I want to put this table into a multiple selection
list, that a user can choose from in a form
My code is drawing a blank though:

//This is my call to the table "staindtypes"
<?php
mysql_select_db($database_lokale, $lokale);
$indque1 = "SELECT * FROM staindtypes";
$inds = mysql_query($indque1, $lokale) or
die(mysql_error());
$row_inds = mysql_fetch_assoc($inds);
why are you doing this?
$totalRows_inds = mysql_num_rows($inds);
$row = mysql_fetch_row;
that's supposed to be a function... no? But then... why is it used here?
?>


//Here is the element and the php to loop it
<form name="form1" id="form1" method="post" action="">
<select name="Ind" size="5" multiple="multiple"
id="Ind">
<option value="">Please Select</option>
<?php
do {
why are you using do..while? It's far easier to just use while
?>
    <option value="<?php echo
$rows['CareerIDs']?>"><?php echo
$row_$result['CareerCategories']?></option>
    <?php
} while ($rows = mysql_fetch_assoc($inds));
  $rows = mysql_num_rows($inds);
  if($rows > 0) {
      mysql_data_seek($inds, 0);
	  $rows = mysql_fetch_assoc($inds);
  }
 ?>

When I load the page it is blank.

Any help would be appreciated.

Stuart

I would suggest writing it like this:
<?php
mysql_select_db($database_lokale, $lokale);
$inds = mysql_query("SELECT * FROM staindtypes", $lokale) or die(mysql_error());
?>
<form name="form1" id="form1" method="POST" action="self.php">
<select name="Ind" size="5" multiple="multiple" id="Ind">
<option selected="selected" value="0">Please Select</option>
<?php
while($ind = mysql_fetch_array($inds, MYSQL_ASSOC)) {
echo '<option value="'.$inds['CareerIDs'].'">'.$inds['CareerCategories'].'</option>';
}
echo '</select></form>';
mysql_free_result($inds); // just in case
?>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux