PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
PastorHank
Forum Contributor
Posts: 117 Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country
Post
by PastorHank » Mon Apr 16, 2007 11:43 am
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
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Mon Apr 16, 2007 12:27 pm
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...
PastorHank
Forum Contributor
Posts: 117 Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country
Post
by PastorHank » Mon Apr 16, 2007 12:37 pm
I'm a little confused by that answer. Would you mind elaborating?
Thank you
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Mon Apr 16, 2007 12:41 pm
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.
PastorHank
Forum Contributor
Posts: 117 Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country
Post
by PastorHank » Mon Apr 16, 2007 12:54 pm
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
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Apr 16, 2007 1:14 pm
Keep your code inside the table, however you cannot put php code within a string.
PastorHank
Forum Contributor
Posts: 117 Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country
Post
by PastorHank » Mon Apr 16, 2007 1:15 pm
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...
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Mon Apr 16, 2007 1:40 pm
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";
?>
PastorHank
Forum Contributor
Posts: 117 Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country
Post
by PastorHank » Mon Apr 16, 2007 1:54 pm
ohhhhh, the lightbulb just went on....thank you