Page 1 of 1

Trying to place a drop down box in a table

Posted: Mon Apr 16, 2007 11:43 am
by PastorHank
this code (used outside a table) works fine

Code: Select all

echo "<form action='bulls.php' method=post>"; 	
echo "<select name='bulllist' size='10'>";

 	while ($row = mysql_fetch_array($result1)) {	
	 extract($row);
  	 echo "<option value=\"".htmlspecialchars($animalid)."\">$animalid";	
	}
	echo "</select>";	
	echo "<input type=submit value=submit>";
	echo "</form>";
this code

Code: Select all

echo "<table align='center' border='2' width='400' bgcolor='#800000' bordercolor='#000000'>";
echo  "<tr>\n
	<td>
	<form action='bulls.php' method=post> 	
	<select name='bulllist' size='10'>
 	while ($row = mysql_fetch_array($result1)) {	
	 extract($row);
  	 <option value=\"".htmlspecialchars($animalid)."\">$animalid
		}
		</select>	
		<input type=submit value=submit>
		</form> 
	</td>
	</tr>";
echo "</table>\n";
Returns only the "}" that is on the line after the animalid and none of the animals.

Thank you

Posted: Mon Apr 16, 2007 12:27 pm
by Begby
Thats because your while loop is inside the string and not outside where it gets executed. Look at the HTML source of the page that is generated...

Posted: Mon Apr 16, 2007 12:37 pm
by PastorHank
I'm a little confused by that answer. Would you mind elaborating?

Thank you

Posted: Mon Apr 16, 2007 12:41 pm
by Begby
Open the page in your browser. View the source. In that source you will see your while loop buried within your table. That is why its not working, your while loop is within your string between the quotes.

Posted: Mon Apr 16, 2007 12:54 pm
by PastorHank
Ok, now I understand, but how should I format it then?

When I put the while loop outside the table, it gives me a table for each item in the list and a new form for each item, rather than putting all the items in the form like I need them to be.

What function should I look at to populate the form correctly?

Thank you

Posted: Mon Apr 16, 2007 1:14 pm
by John Cartwright
Keep your code inside the table, however you cannot put php code within a string.

Posted: Mon Apr 16, 2007 1:15 pm
by PastorHank
Now I'll admit that sometimes I'm dumber than dirt, would you mind giving me an example of how I can accomplish what I'm trying to do...

Posted: Mon Apr 16, 2007 1:40 pm
by RobertGonzalez

Code: Select all

<?php
echo '<table align="center" border="2" width="400" bgcolor="#800000" bordercolor="#000000">';
echo '<tr>
        <td>
        <form action="bulls.php" method="post">  
        <select name="bulllist" size="10">';
        while ($row = mysql_fetch_array($result1)) {   
         extract($row);
         echo '<option value="' . htmlspecialchars($animalid) . '">' . $animalid . '</option>';
        }
        echo '</select>       
              <input type="submit" value="submit">
              </form>
        </td>
        </tr>';
echo '</table>' . "\n";
?>

Posted: Mon Apr 16, 2007 1:54 pm
by PastorHank
ohhhhh, the lightbulb just went on....thank you

Posted: Mon Apr 16, 2007 3:44 pm
by RobertGonzalez
You're welcome. :)