0

I am trying to make a form that show users name and I am having a little trouble with this part. The ' ' and " " marks dont quite work how they are supposed to. Im trying to echo the options in drop down menu and some how the $wholenames and the last " sign appear in the wrong part of the page. Could someone please tell me what is the correct way of doing this?

Thanks

 echo' "<option>'; echo $wholenames; echo'</option>"';

Actually I had looked it wrong it is a little bit more complex. Below you can see the code. The whole dropdown menu does not appear. The wholenames integer appears, but the menu does not...

echo'

      <label for="addusertogroup">Add user  to an existing group:</label>
      <select name="addusertogroup" id="addusertogroup">
      ';  if(mysql_num_rows($userresult)) 
        { 
            while($row2 = mysql_fetch_assoc($userresult)) 
            { 

            $wholename = array("$row2[f_name] $row2[s_name]");

                foreach ($wholename as $wholenames) {   

                    echo "<option>$wholenames</option>";


                }
            } 
         } 
        else {
            echo "<option>No Names Present</option>";  
        } 

3 Answers 3

3

To make it work, simply do this:

echo "<option>";
echo $wholenames;
echo "<option>";

or this:

echo "<option>$wholenames</option>";

or this:

echo '<option>'.$wholenames.'</option>'; 

All will work, just up to you which one you pick.

Sign up to request clarification or add additional context in comments.

2 Comments

Or echo '<option>'.$wholenames.'</option>';
or take out the array which doesn't look like it's needed. echo '<option>'.$row2[f_name].' '.$row2[s_name].'</option>';
0

You shouldn't have " before <option> and after </option>

It should be something like

echo "<option>". echo $wholenames; echo "</option>";

Also, if $wholenames is an array, you'd better iterate over it:

foreach ($wholenames as $name){
    echo "<option>". echo $name; echo "</option>";
}

Comments

0

Any text for options in a HTML SELECT box are written inside the tag. If you don't put your text between the <option> tags the browser will try to insert it to the select box's DOM.

So you could change your code to this:

echo '<option value="myvalue">"' . $wholenames . '"</option>';

Haven't actually tested this code.

Update if the Quotation mark was not meant to be in the output you would simply need to write:

echo '<option value="myvalue">' . $wholenames . '</option>';

In php you can use both " " and ' ' with strings.

1 Comment

Where is the broken string? Are talking about PHP seeing it as a broken string or the HTML?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.