I have the following drop down list populated from a db query.
I am struggling to figure out a way to add items selected from this dropdownbox
to essentially a list like a shopping cart which allows me to make multiple additions from this drop down box.
Can you anyone guide me with this
<?php
mysql_connect('localhost', 'blah', 'password');
mysql_select_db('reporting');
$sql = "SELECT DISTINCT ProductNumber, Description FROM Stock WHERE ProductGroup ='800'";
$result = mysql_query($sql);
echo "<select name='PRODS'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Description'] . "'>" . $row['Description'] . "</option>";
}
echo "</select>";
?>
Try:
echo "<select name='PRODS' multiple>";
With this you will be able to select multiple values form the select box.
try this....
<?php
mysql_connect('localhost', 'blah', 'password');
mysql_select_db('reporting');
$sql = "SELECT DISTINCT ProductNumber, Description FROM Stock WHERE ProductGroup ='800'";
$result = mysql_query($sql);
echo "<select name='PRODS' multiple>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Description'] . "'>" . $row['Description'] . "</option>";
}
echo "</select>";
?>
Related
I want to create a select menu option form SQL table with two condition
one is table id base where no userid and second is userid base.
include '../conn.php';
$userid=$_SESSION['currentid'];
$sql = "SELECT wname FROM bankw where UserId='$userid' INNER JOIN bankw where id='1' ";
$result = mysqli_query($con,$sql);
echo "<select class='form-control' id='item' name='item'>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['wname'] ."'>" . $row['wname'] ."</option>";
}
echo "</select>";
Both are show in same option menu but my code does not show any option or show only userid base option
just change and i got which i needed
$userid=$_SESSION['currentid'];
$sql = "SELECT wname FROM bankw where UserId='$userid' or id='1' ";
$result = mysqli_query($con,$sql);
echo "<select class='form-control' id='item' name='item'>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['wname'] ."'>" . $row['wname'] ."</option>";
}
echo "</select>";
Thanks all
Basically trying to populate a drop-down select bar from a table called "Cars" with data in the "VIN" column. It's giving me a blank.
<form>
<label>VIN:</label>
<select name="formVIN">
<?php
$sql = "SELECT VIN FROM Cars";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['VIN'] . "'>" . $row['VIN'] . "</option>";
}
echo "</select>";
?>
</form>
I would like to take it a step further by displaying ONLY the VIN's of those cars not sold. I have a column in the table "Cars" that has either a 'Y' or 'N' if sold. So I would like it to show only the ones with 'N' as well.
$sql = "SELECT VIN FROM Cars WHERE VSold='N'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<option value=" . $row["VIN"] . ">" . $row["VIN"] . "</option>";
}
} else {
echo "<option value=''>ALL SOLD</option>";
}
Figured I'd try a different approach, and while the WHILE did make sense, this isn't too bad either. I'm still learning, a lot, and some of your comments helped me see things from a different perspective. I tried a lot of different options, thank you all.
How to get the scheduleID value from a comboBox within a specific MovieID value from another comboBox?
comboBox Movie
<?php
$query = "select * from ref_movies ORDER BY MovieID";
$result = mysql_query($query) or die (mysql_error());
echo '<select name="MovieID" ><option value="">---Select Movie---</option>';
while ($row = mysql_fetch_assoc($result))
{
echo "<option value='" . $row['MovieID'] ."'>" . $row['MovieTitle'] ."</option>";
}
echo '</select>';
?>
comboBox Schedule
<?php
$query = "select * from schedule ORDER BY scheduleID";
$result = mysql_query($query) or die (mysql_error());
echo '<select name="ScheduleID" ><option value="">---Select Time---</option>';
while ($row = mysql_fetch_assoc($result))
{
echo "<option value='" . $row['ScheduleID'] ."'>" . $row['MovieDATETIME'] ."</option>";
}
echo '</select>';
?>
Put the two PHP scripts in separate files.
Set the form action in the first one to the URL of the second one.
Read the value from $_GET['MovieID'].
This is an addition to the previous questions I asked. In my drop down box for engravers I would like the box to collect the surnames from three fields, Engraver1Surname, Engraver2Surname and Engraver3Surname. I also want each name only to appear once and to be in alphabetical order. My code doesn't work which means I've got it wrong again. This stuff is really challenging and I'm loving it but I don't want to be a serial pest.This is what I tried.
$sql = "SELECT DISTINCT Engraver1Surname, Engraver2Surname, Engraver3Surname FROM engravers Where Engraver1Surname, Engraver2Surname, Engraver3Surname <> '' AND Engraver1Surname, Engraver2Surname, Engraver3Surname IS NOT NULL ORDER by Engraver1Surname, Engraver2Surname, Engraver3Surname";
$result = mysql_query($sql);
echo "<select name\\='Engraver1Surname'>";
echo "<option value='$_POST'>Engraver</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Engraver1Surname'] . "'>" .$row['Engraver1Surname'] . "</option>";
}
echo "</select>";
$name=array('Engraver1Surname','Engraver2Surname','Engraver3Surname');
$option=array();
while ($row = mysql_fetch_array($result)) {
for($x=0;$x<3;$x++){
$option.=$row[$name[$x]];
}
}
asort($option);
for($y=0;$y<sizeof($option);$y++){
echo "<option value='" . $option[$y]. "'>" .$option[$y] . "</option>";
}
echo "</select>";
Hope it fix to your question
I have a table cene_pretplatne_stanarske which has two columns 'lice' and 'cene'. The first column 'lice' should populate a select, dropdown menu, and the other column, 'cene', should populate a input box, based on the selection of the dropdown menu. I tried this:
<?php
mysql_connect('localhost', 'xxxxx', 'xxxxxxx');
mysql_select_db('xxxxxxx');
mysql_set_charset('utf8');
$sql = "SELECT * FROM cene_pretplatne_stanarske";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$cena = $row ["cena"];
$sql = "SELECT lice FROM cene_pretplatne_stanarske WHERE lice LIKE 'C0%'";
$result = mysql_query($sql);
echo "<select name='lice' onchange='document.getElementById(\'form1\').submit();'>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['lice'] . "'>" . $row['lice'] . "</option>";
}
echo "</select>";
echo "<input type='text' value='$cena' />";
?>
but it returns empty select box, and the input box with the value of the first row of 'cene' column. Please help.
Check how many (if any) results are being returned:
$i=0;
while ($row = mysql_fetch_assoc($result)) {
echo "<option value='" . $row['lice'] . "'>" . $row['lice'] . "</option>";
$i++;
}
echo $i after the end of </select>