The Below code we are using. Please check and update:
`
dashboard
</div>
<div class="form-group">
<label for="to_user">Turbine</label>
<select name="to_user" class="form-control">
<option value="pick">--Select All--</option>
<option> <?php
$query = "SELECT DISTINCT Turbine FROM [JMDWF].[dbo].[TENAVG]";
$sql = sqlsrv_query($link,$query);
$row = sqlsrv_num_rows($sql);
$menu = "";
echo "<select name='to_user'>";
while ($row = sqlsrv_fetch_array($sql)){
/* echo "<option value='". $row['Turbine'] ."'>" .$row['Turbine'] ."</option>" ;*/
$menu.="<option>".$row['Turbine']."</option>";
}
echo "$menu";
?>
</option>
</select>
</div>`
Still we getting output out of the drop down list. I need to show the values in drop down.
Your are printing the output from PHP into your <option></option> node of the html - it won't be visible.
Try this instead:
<div class="form-group">
<label for="to_user">Turbine</label>
<?php
$query = "SELECT DISTINCT Turbine FROM [JMDWF].[dbo].[TENAVG]";
$sql = sqlsrv_query($link,$query);
$row = sqlsrv_num_rows($sql);
$menu = "";
echo "<select name='to_user'>";
echo "<option value='pick'>--Select All--</option>";
while ($row = sqlsrv_fetch_array($sql)){
/* echo "<option value='". $row['Turbine'] ."'>" .$row['Turbine'] ."</option>" ;*/
$menu.="<option>".$row['Turbine']."</option>";
}
echo "</select>";
echo "$menu";
?>
</div>`
Related
I am trying to create some code to do a list of components in mysql.
Something like this
decod - 1,2,3,4,5
and to make it in drop-down listlike this
decod (dorplist) 1
2
3
4
5
I tried this one:
<?php
$mysqli = mysqli_connect("host", "username", "password", "name");
$result = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli));
while ($row = mysqli_fetch_array($result)) {
$org = str_replace("," , "'>", $row['fill']."");
$replace = str_replace("," , "
".$org."</option><option value='", $row['fill']."'>");
echo "<input type='hidden' name='compo' value='".$row['compon']."'>".$row['compon']."";
echo "<select name='fill'>";
echo "<option value='".$replace."'>".$replace."</option>";
echo "</select>";
}
// Free result set
mysqli_free_result($result);
/* close connection */
$mysqli->close();
?>
and do make it output to an XML
but I don't know how! I output like this
<input type='hidden' name='compo' value='DECODERS'>DECODERS
<select name='fill'>
<option value='1010'>20'>30'>40</option>
<option value='2010'>20'>30'>40</option>
<option value='3010'>20'>30'>40</option>
<option value='40'>'>1010'>20'>30'>40</option>
<option value='2010'>20'>30'>40</option>
<option value='3010'>20'>30'>40</option><option value='40'></option>
</select>
<input type='hidden' name='compo' value='DECODERS'>DECODERS
<select name='fill'>
<option value='10'>10</option>
</select>
First create the <select> outside the while loop. Then iterate over the rows to add the elements.
I'm not sure what you're trying to accomplish with your str_replace calls, so I removed them.
Something like this might get you started in the right direction:
<?php
$result = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli));
echo "<select name='fill'>";
echo "<input type='hidden' name='compo' value='".$row['compon']."'>".$row['compon']."";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='".$row['fill']."'>".$row['fill']."</option>";
}
echo "</select>";
mysqli_free_result($result);
$mysqli->close();
?>
I search for answers here but haven't found a solution.
I have also added picture of the error.
I want the data to go to the first drop-down list ( above the error)
I think the method I try to perform is also create drop-down list, am I correct?
<form name="message" action="" method="post" onsubmit="" accept-charset="utf-8">
<div class="form-group">
<label id="senderName">שם השולח:</label>
</div>
<div class="form-group">
<label for="to_user">מען:</label>
<select name="to_user" class="form-control">
<option value="pick">בחר מהרשימה</option>
<?php
$sql = \mysqli_query("SELECT name From users");
$row = mysqli_num_rows($sql);
echo "<select name='to_user'>";
while ($row = mysqli_fetch_array($sql)){
echo "<option value='". $row['name'] ."'>" .$row['name'] ."</option>" ;
}
echo "</select>" ;
?>
</select>
</div>
picture of the error
In MySQLi, the first parameter of a query needs to be the database connection. Also, there's no need to add a \ before the statement.
$sql = \mysqli_query("SELECT name From users"); should be $sql = mysqli_query($con, "SELECT name From users");
Note: replace $con with your database connection variable!
As you mentioned that you wanted the result from the database to go inside the select form, simply adjust your code to look like this:
<select name="to_user" class="form-control">
<option value="pick">בחר מהרשימה</option>
<?php
$sql = mysqli_query($con, "SELECT name From users");
$row = mysqli_num_rows($sql);
while ($row = mysqli_fetch_array($sql)){
echo "<option value='". $row['name'] ."'>" .$row['name'] ."</option>" ;
}
?>
</select>
<div class="row form-group">
<div class="col col-md-3">
<label for="email-input" class=" form-control-label"> Vehicle</label>
</div>
<div class="col-12 col-md-9">
<select name="car_id" id="car_id" class="form-control-label" >
<?php
$list = mysqli_query($conn,"SELECT * FROM `vehicle_registration` where `status`='0' ");
while ($row_ah = mysqli_fetch_assoc($list)) {
?>
<option value="<?php echo $row_ah['id']; ?>"><?php echo $row_ah['car_no']; ?></option>
<?php } ?>
</select>
</div>
</div>
<label><b>Select Steam: </b></label>
<select id="study">
<option value="" selected="selected" disabled="">---Selected---</option>
<?php
$query = "SELECT study FROM details";
$query_run = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($query_run)) {
echo "<option value='".$row['study']."'>".$row['study']."</option>";
}
?>
</select>
I am trying to edit my form. I want to get selected value selected in selection list.
I have created function to store values in database, and it works. Below is html code I use and function below to insert values in database.
// insert values in database
<label>Dobavljač</label>
<select class="form-control" name="dobavljac" required>
<?php dobavljac() ?>
</select>
function dobavljac(){
$sql=mysqli_query($link, "SELECT * FROM `partneri` WHERE `Dobavljac`='1'
order by `PartnerId` asc ");
echo '<option value="">Izaberi dobavljača</option>';
while($record = mysqli_fetch_array($sql)) {
echo '<option value= "' .$record['PartnerId']. '">' . $record['PartnerNaziv'] . ' </option>';
}
}
// edit values
First I retrieve information from database
$id=$_GET['id'];
$sql = "SELECT * FROM materijali where Id=$id ";
$q = $conn->query($sql);
$r = $q ->fetch();
if ($r) {
$dobavljac=$r['Dobavljac'];
I want to get selected value in box
<label>Dobavljač</label>
<select class="form-control" name="dobavljac" value="<?php echo $dobavljac; ?>">
<?php dobavljac() ?>
</select>
Probably I am not doing it the right way, any advice would be appreciated
Try this
<label>Dobavljač</label>
<select class="form-control" name="dobavljac" value="<?php echo $dobavljac; selected?>">
<option value=<?php echo $dobavljac?> selected>
<?php dobavljac() ?>
</option>
</select>
Try this...
$id=$_GET['id'];
$sql = "SELECT * FROM materijali where Id=$id ";
$q = mysql_query($query);
echo "<select name="dobavljac" class="form-control">";
while (($row = mysql_fetch_row($q)) != null)
{
echo "<option value = '{$row['Dobavljac']}'>";
echo $row['Dobavljac'];
echo "</option>";
}
echo "</select>";
My box is populating from my database but I would like to show the drop down box blank until it is clicked to select. Not quite sure how to do that. Thanks in advance
<select type="text" name='id' id="inputItem" placeholder="Item #1" class="form-control">
<?php
require ('dbconnect.php');
$result = $con->query("select id, item from items");
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['item'];
echo '<option value="'.$id.'">'.$name.'</option>';
}
echo "</select>";
mysqli_close($con);
?>
</div>
Add <option>Choose One...</option> immediately after your first line.
you could add blank option before while loop, as:
...
echo '<option value="">Select</option>';
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['item'];
echo '<option value="'.$id.'">'.$name.'</option>';
}
...
<select type="text" name='id' id="inputItem" placeholder="Item #1" class="form-control">
<option value=''>Select First</option>
Before your while loop:
echo '<option value="">--- Select ---</option>';
We managed to get the drop down list menu however, we are having difficulties getting the data from sql. So far, this is what we got.
<select>
<option id="">--Select jobscope--</option>
<?php
$con=mysqli_connect("host","user","password","database");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$getIT = mysqli_query("SELECT job_title FROM `job_details`");
while($viewIT = mysqli_fetch_array($getIT)) {
}
?>
<option id="<?php echo $viewIT['job_title']?>"<?php echo $viewIT['job_title']?></option>
</select>
Shouldn't be like this ? with tag inside WHILE LOOP
while($viewIT = mysql_fetch_array($getIT)) {
<option id="<?php echo $viewIT['job_title']?>"<?php echo $viewIT['job_title']?></option>
}
$query = "SELECT * FROM test_groups_tb WHERE user_id='$userid'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
$dd .= "<option value='{$row['group_id']}'>{$row['group_name']}</option>";
}
Try this,
<option value="">--select--</option>
<?php
while($rec = mysql_fetch_assoc($result)) {
?>
<option value="<?=$rec['job_title']?>"><?=$rec['job_title']?></option>
<?php }
}?>
</select>
I am not from php background. Try this.
<?php
$query = "SELECT job_title FROM job_details";
$result = $mysqli->query( $query );
echo '<select id="domain_account" name="domain_account" class="txtBox">';
echo '<option value="">-select-</option>';
while ($row = $result->fetch_assoc()){
?>
<option value="<?php echo $row['job_title']; ?>"><?php echo $row['job_title']; ?></option>
<?php
}
echo "</select>";
?>
Better use PDO or MYSQLi . MYSQL* is depriciated
U need to use that <option id="<?php echo $viewIT['job_title']?>"<?php echo $viewIT['job_title']?></option> line b/w while loop
$getIT = mysql_query("SELECT job_title FROM `job_details`");
while($viewIT = mysql_fetch_array($getIT)) {?>
<option id="<?php echo $viewIT['job_title']?>"<?php echo $viewIT['job_title']?></option>
<?hp }?>