Jump to content

Recommended Posts

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">.....???

<?php
php 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";
   }
?>
Link to comment
https://forums.phpfreaks.com/topic/26344-dynamic-form-population-almost-solved/
Share on other sites

It doesnt matter, you can do that.
This is the same thing as-

[code]<?php
php 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.
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";
    }
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 anything
other 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";
          }

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.
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 fourm

The 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 />";
[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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.