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
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.
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>";
?>
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>
I have a table called Parts, (PartID, PartName, Cost) and I have PHP populating a Drop down box with the PartID's. I want it to when a user selects a Part ID, it populates one text box with the Part's name and the other box, with the Part's cost.
Here's what my Code look's like for the drop down box if it helps any :)
$sql = "SELECT PartID FROM Parts WHERE PartID LIKE 'C0%'";
$result = mysql_query($sql);
echo "<select name='PartID'>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['PartID'] . "'>" . $row['PartID'] . "</option>";
}
echo "</select>";
I don't know what you're exactly trying to do, but this sounds more like javascript, to me.
Set a onchange function on your dropdown and get it to fill the fileds with name and cost that you would have stock into a javascript array before. Sounds ugly but it would work
You'll have to POST back to retrieve the values, either with a simple POST or an AJAX POST
if (!empty($_POST)) {
$partid = $_GET["PartID"];
$sql = "SELECT * FROM Parts WHERE PartID = '$partid'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$part_name = $row ["PartName"];
$part_cost = $row ["PartCost"];
}
$sql = "SELECT PartID FROM Parts WHERE PartID LIKE 'C0%'";
$result = mysql_query($sql);
echo "<select name='PartID' onchange='document.getElementById(\'form1\').submit();'>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['PartID'] . "'>" . $row['PartID'] . "</option>";
}
echo "</select>";
echo "<input type='text' value='$part_name' />";
echo "<input type='text' value='$part_cost' />";