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();
?>
Related
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>`
<?php
$mysqli = mysqli_connect***;
$result = mysqli_query($mysqli, 'SELECT * FROM componnets LEFT JOIN fill ON componnets.id=fill.Uid') or die(mysqli_error(mysqli));
$resultCOM = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli));
while ($rowCOM = mysqli_fetch_array($resultCOM)) {
echo "<input type='hidden' name='compo' value='".$rowCOM['compon']."'>".$rowCOM['compon']."";
echo "<select name='fill'>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='".$row['num']."'>".$row['num']."</option>";
}
echo "</select>";
}
// Free result set
mysqli_free_result($result);
/* close connection */
$mysqli->close();
?>
the question is this, i need to combine between 2 sql.
the result i need is that:
<input type='hidden' name='compo' value='decod'>decod
<select name='fill'><option value='100'>100</option>
</select>
<input type='hidden' name='compo' value='rg5.9'>rg5.9
<select name='fill'><option value='100'>100</option>
<select name='fill'><option value='100'>200</option>
<select name='fill'><option value='100'>300</option>
</select>
i try all combins and nothing..
the output in now is like this
<input type='hidden' name='compo' value='decod'>decod
</select>
<input type='hidden' name='compo' value='rg5.9'>rg5.9
<select name='fill'><option value='100'>100</option>
<select name='fill'><option value='100'>300</option>
</select>
the mysql is bulld like this
fill - num uid
100 3
300 1
componnets - id compon
1 decod
2 rg59
3 rg6
thx for help.
I am using the following PHP code to retrieve the team name from the mysql db table team_details which contains 2 columns,team_id and team_name
<?php
mysql_connect("", "", "");
mysql_select_db("db_name");
$data = mysql_query("SELECT team_name FROM team_details");
print "Team A:";
Print "<select name="dropdown">";
while($info = mysql_fetch_array( $data ))
{
Print "<option value='".$info['team_name']."'>".$info['team_name'] . "</option> ";
}
Print '</select>';
?>
Full code
Team and Players selection for the match
Choose the teams for the match
";
while($info = mysql_fetch_array( $data ))
{
echo "".$info['team_name'] . " ";
}
echo '';
?>
VS
Team B:
<select id="team2" disabled="true">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<button id="sub" disabled="true" name ="choose" onclick="load_players();"> Choose Players</button>
<button type="reset" value="Clear" onclick="reset_load();"> Clear</button>
</form>
</div>
</body>
you error may be here:
Print "<select name="dropdown">";
you need to escpae the double quotes:
Print "<select name=\"dropdown\">";
First of all, you have syntax error here:
Print "<select name="dropdown">";
Escape quotes like this:
Print "<select name='dropdown'>";
Second, use mysql_fetch_assoc instead of mysql_fetch_array, so your code looks like this:
while($info = mysql_fetch_assoc( $data ))
{
Print "<option value='".$info['team_name']."'>".$info['team_name'] . "</option> ";
}
And check your mysql_connect in order to have right values (Host name, user, password)
try following code, replace host, db_username, db_password and db_name
mysql_connect("host", "db_username", "db_password");
mysql_select_db("db_name");
$data = mysql_query("SELECT team_name FROM team_details");
echo "Team A:";
echo "<select name='dropdown'>";
while($info = mysql_fetch_array( $data ))
{
echo "<option value='".$info['team_name']."'>".$info['team_name'] . "</option> ";
}
echo '</select>';
I was wondering how one would go about having this code below to have the option from the user's profile to display the correct state. Right now it defaults to the blank line.
<select id="state" name="state" class="input-xlarge form-control">
<option value=""></option>
<?php
$result = $db->select("SELECT * FROM as_states ORDER BY statename ASC");
foreach($result as $country)
{
echo "<option value=\"";
echo $country['stateid'];
echo "\">";
echo $country['statename'];
echo "</option>";
}
?>
</select>
Someone told me on here in the past how to do it this way (below), which is the older PHP version and wanted to know how to make it work in the above statement.
<?php
$sql="SELECT * FROM countries ORDER BY countrypicks DESC,countryname ASC";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result))
{
$countryid=$row["countryid"];
$countryname=$row["countryname"];
$selected = ($countryid == $merchcountry) ? 'selected="selected"' : '';
$options.="<option value=\"$countryid\" $selected>$countryname</option>";
}
?>
<SELECT NAME="merchcountry">
<option>-------</option>
<? echo $options; ?>
</SELECT>
Thank you.
the html should look like
<option value="id" selected>name</option>
(or selected="selected" if you need to be xhtml compatible )
so something like:
echo "<option value=\"";
echo $country['stateid'];
if ( $country['stateid'] == $user_state ) echo " selected";
echo "\">";
echo $country['statename'];
echo "</option>";
also:
SELECT * FROM countries ORDER BY countrypicks DESC,countryname ASC
is overkill if you only need stateid and statename.
I need to submit a form with multiple values
<form onsubmit="return false;">
<?php
echo "<select id=\"uname\" name=\"uname[]\" multiple>\n";
$sql = "SELECT * FROM users ORDER BY surname ASC";
$res = $db->query($sql);
while($row = $res->fetch()){
$strA = $row["uname"];
$strB = $row["givenname"];
$strC = $row["surname"];
echo "<option value=\"$strA\">$strC, $strB</option>\n";
}
echo "</select>\n";
echo "<input type='button' name='endreBruker' value='OK' onclick='javascript:".$_POST['edit']."(this.form)'/>";
?>
and pass the POST values through this to newNote.php
function newNote(form) {
$('#main').load ('newNote.php', {'uname[]' : form.uname.value} );
}
Problem is I only receive an array with a single value.
Check out jQuery's serialize(). You could then write something like this:
function newNote(form) {
$('#main').load ('newNote.php', $(form).serialize() );
}
You may try something like that:
<select name="theselect" onchange="this.selectedIndex = 1;">
<option value="Red">Red</option>
<option value="Green" selected="selected">Green</option>
<option value="Blue">Blue</option>
</select>
Green color always been selected, but user may see other color, but don`t pick them