I want to put the select clause in php html.
here my code:
<?php
for($index=1; $index<=$content->option->dynamic_field_index; $index++){
echo "<td><select name='kboard_option_product'
id='kboard_option_product{$index}' data-placeholder='selectProduct'>";
echo "<optgroup value='0' label='products'>";
echo "<option value='windows'>windows</option>";
echo "<option value='linux'>linux</option>";
echo "<option value='unix'>unix</option>";
echo "</optgroup></select></td>";
}?>
How can I fix it?
I want to do that in
If you look at the options below you will save the data like this, but if you use echo, you have to match php syntax and html syntax.
<option value="window"<?php if($content->option->product == 'window'):?> selected<?php endif?>>window</option>
What I want to do is to use the for statement in the php clause and use the tag with echo to show it as html
Just use the following ,
function php_selectbox(){
ob_start();
?>
//Place your html here and echo the function outside.
<?php
return ob_get_clean();
}
Related
I want to get the array values in dropdown option menu.This is my code so far
<?php
$names=array("jan","feb","mar");
foreach($month_names as $mn)
{
echo "<select>";
echo "<option>$mn</option>";
echo "</select>";
}
?>
But the code is creating a new select tag for each value.
How can I Get all array value inside a select tag?
Any help is much appriciated, thanks!
Regards: Amit Perez
Please try this code, In your code you were including <select></select> inside foreach loop, that's why you were getting 3 select tag.
<?php
$names=array("jan","feb","mar");
echo "<select>";
foreach($month_names as $mn)
{
echo "<option>$mn</option>";
}
echo "</select>";
Please change your code as follows
<?php
$month_names=array("jan","feb","mar");
echo "<select>";
foreach($month_names as $mn)
{
echo "<option>$mn</option>";
}
echo "</select>";
?>
I am attempting to create a drop down of items from a JSON file located on a remote server. The drop down appears to be populating (as there are options to choose from), but the text is not visible. I have attempted changing the style color (worth a try, right?) and multiple browsers.
<?php
echo '<select name="version" style="width: 300px">';
$url = 'http://s3.amazonaws.com/Minecraft.Download/versions/versions.json';
$jsonData = file_get_contents($url);
$jsonDataObject = json_decode($jsonData);
foreach($jsonDataObject->versions as $option){
echo '<option value=' . $option->type . '</option>';
}
echo '</select>';
?>
Thanks in advance for any assistance offered.
You are not populating the display text
echo "<option value= { $option->type } >{$option->type}</option>";
This is a little different from your statement, but the logic is the same. You need to write some text between option tags
<option value="val">displayText</option>
It should be something like-
echo '<option value=' . $option->type . '>'.$SOME_VALUE_HERE.'</option>';
// ^
<select name="QuestionType" data-validation-required-message="Choose the Question Type" class="form-control">
<?php
foreach ($drpquestiontype as $row) {
$QuestionTypeId = $row['QuestionTypeId'];
$QuestionTypeName = $row['QuestionTypeName'];
echo '<option value='.$QuestionTypeId.'>'.$QuestionTypeName.'<option>';
}
?>
</select>
Please help
This line has missing quotes. The single quotes break you out of the echo command, so the resulting html has no quotes around the value attribute. You're also missing a slash on the closing option tag. This:
echo '<option value='.$QuestionTypeId.'>'.$QuestionTypeName.'<option>';
Generates this:
'<option value=6>Name<option>';
The PHP code should be:
echo '<option value="'.$QuestionTypeId.'">'.$QuestionTypeName.'</option>';
Hello I need to fix a problem on my PHP code. When I write the value name="" and id="" aren't found. Here's the code:
<?php
$tipos= $eachoption['option_value'];
$categorias='';
$cats = explode(",",$tipos);
echo "<select name=\"option_<?php echo $eachoption['option_id'];?>[]\" id=\"<?php echo $_POST['option_'.$eachoption['option_id']][$i];?>\">";
foreach($cats as $cat){
$cat = trim($cat);
$categorias .= "<option>". $cat ."</option>";
}
echo $categorias;
echo "</select>";
?>
Thanks! I think that maybe is for " or ' inside echo.
Your PHP syntax is incorrect. You cannot embed PHP-within-PHP. e.g.
<?php
$foo = "<?php echo 'bar' ?>";
will NOT execute that echo call. You are assigning the literal characters <, ?, p, etc... to a string.
Since you're using double-quoted strings, you don't need the echoes for simple variable insertions at all:
echo "<select name=\"option_{$eachoption['option_id']}[]\" id=\"" . $_POST['option_'.$eachoption['option_id']][$i]; . "\">";
^^^^^^^^^^^^^^^^^^^^^^^^^^
note that the second $_POST does require breaking out of string mode, since you're dynamically creating the array key.
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>";
}
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.
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>";
}
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.