tet3828 Posted November 6, 2006 Share Posted November 6, 2006 In the following script...Why did the coder Leave PHP ?> Make the <select> statement and go back into it <?php?would this code still work if it stayed in PHP and used the echo "<select name="blah">.....???<?phpphp require("config.php");$result = mysql_query("SELECT * FROM spell");?><select name="wordlist"> <option value="1" selected>Select Word</option><?php while($row = mysql_fetch_array($result)){ echo "<option value=\"$row['words']\">$row['words']</option>\n"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/ Share on other sites More sharing options...
Orio Posted November 6, 2006 Share Posted November 6, 2006 It doesnt matter, you can do that.This is the same thing as-[code]<?phpphp require("config.php");$result = mysql_query("SELECT * FROM spell");echo '<select name="wordlist">\n<option value="1" selected>Select Word</option>'; while($row = mysql_fetch_array($result)){ echo "<option value=\"$row['words']\">$row['words']</option>\n"; }?>[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/#findComment-120438 Share on other sites More sharing options...
bqallover Posted November 6, 2006 Share Posted November 6, 2006 It's just a matter of preference I think. It'll still work if echo'd, but just being pedantic you'd have to be careful to either escape the double-quotes OR wrap the echo-text in single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/#findComment-120441 Share on other sites More sharing options...
tet3828 Posted November 6, 2006 Author Share Posted November 6, 2006 what would cause these lines to have a Parse error:parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/t/e/t/tetunity/html/shell/data/edit.php on line 202??? while($row = mysql_fetch_array($result)){echo "<option value=\"$row['itemCat']\">$row['itemCat']</option>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/#findComment-120478 Share on other sites More sharing options...
Orio Posted November 6, 2006 Share Posted November 6, 2006 Change this line-echo "<option value=\"$row['itemCat']\">$row['itemCat']</option>\n";To-echo "<option value=\"".$row['itemCat']."\">".$row['itemCat']."</option>\n";Orio. Quote Link to comment https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/#findComment-120487 Share on other sites More sharing options...
tet3828 Posted November 6, 2006 Author Share Posted November 6, 2006 Maybe my question was misunderstood or my script is inncorrect.for my 'products' database is setup as follows:each "product" has "itemName, itemDesc, itemCat.....I was hoping to have a dropdown menu filled with ANY values that maybe listed in the itemCat column. for example even if I went to myphpadmin and added a new item with a new catagory that catagory would appear in my dropdown. for some reason this script isn't populating my dropdown with anythingother then the "select a catagory" option. any suggestions as to why this might be happening???? echo "<select name='newName'>"; echo "<option value='1' selected>Select a Catagory</option>"; echo "<input type='submit' name='submitfour' value='Submit' /><br />"; $result = mysql_query("SELECT itemCat FROM products"); while($row = mysql_fetch_array($result)){ echo "<option value=\"".$row['itemCat']."\">".$row['itemCat']."</option>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/#findComment-120556 Share on other sites More sharing options...
Orio Posted November 6, 2006 Share Posted November 6, 2006 Try this:[code]<?php echo "<option value=\"".$row['itemCat']."\">".$row['itemCat']."</option>\n";$result = mysql_query("SELECT DISTINCT itemCat FROM `products`"); while($row = mysql_fetch_array($result)){ echo "<option value=\"".$row['itemCat']."\">".$row['itemCat']."</option>\n";}echo "</select>";?>[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/#findComment-120560 Share on other sites More sharing options...
tet3828 Posted November 6, 2006 Author Share Posted November 6, 2006 Almost there! the Dynamic form is [i][b]almost[/b][/i] ERROR free.Thanks once again [b]Orio you're a Genius[/b]! Thanks once again for all the time you devote to this fourmThe only problem I am having now is: the loop is displaying one extra line in my dripdown menu. The extra line is blank. What is causing this? and how can I eradicate it?echo "<select name='newName'>";echo "<option value='1' selected>Select a Catagory</option>";echo "<option value=\"cat".$row['itemCat']."\">".$row['itemCat']."</option>\n";$result = mysql_query("SELECT itemCat FROM `products`"); while($row = mysql_fetch_array($result)) { echo "<option value=\"".$row['itemCat']."\">".$row['itemCat']."</option>\n";}echo "</select>";echo " <input type='submit' name='submitfour' value='Submit' /><br /><br />"; Quote Link to comment https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/#findComment-120612 Share on other sites More sharing options...
sasa Posted November 6, 2006 Share Posted November 6, 2006 [code][codegecho "<select name='newName'>";echo "<option value='1' selected>Select a Catagory</option>";echo "<option value=\"cat".$row['itemCat']."\">".$row['itemCat']."</option>\n"; //<= this is extra line remove it$result = mysql_query("SELECT itemCat FROM `products`"); while($row = mysql_fetch_array($result)) { echo "<option value=\"".$row['itemCat']."\">".$row['itemCat']."</option>\n";}echo "</select>";echo " <input type='submit' name='submitfour' value='Submit' />";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/#findComment-120626 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.