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
Related
I have created a html form. In that I have 2 drop down lists. Drop-down list1 retrieves values from sql database table and displays over there. Now I want to display another drop-down list with input from drop-down list 1.
This is my code:
<label for="bname">Select a Building</label>
<?php
session_start();
include 'db_connection.php';
$conn = OpenCon();
$sql = "SELECT bname FROM building_details";
$result = mysqli_query($conn, $sql);
echo "<select name='bname'>";
while ($row = mysqli_fetch_array($result)){
echo "<option value='". $row['bname'] ."'>".$row['bname'] ."</option>";
}
echo "</select>";
echo "<label for='rtype'>Select a rtype</label>";
$sql2 = "SELECT rtype FROM room_details WHERE bname='bname'";
$result2 = mysqli_query($conn,$sql2);
echo "<select name='rtype'>";
while ($row2 = mysqli_fetch_array($result2)){
echo "<option value='". $row2['rtype'] ."'>".$row2['rtype'] ."</option>";
}
echo "</select>";
Here once bname value From building_details is selected then based on that input I need to display another dropdown list which is the rtype column from room_details table.
Can some one help me with this???
This is the only way I found to do it.
I hope it's what you're looking for!
<label for="bname">Select a Building</label>
<?php
session_start();
include 'db_connection.php';
$conn = OpenCon();
$sql = "SELECT bname FROM building_details";
$result = mysqli_query($conn, $sql);
$bnames = "";
echo "<select name='bname'>";
while ($row = mysqli_fetch_array($result)){
echo "<option value='". $row['bname'] ."'>".$row['bname'] ."</option>";
$bnames .= $row['bname'] . ", ";
}
$bnames = substr($bnames, 0, -2);
echo "</select>";
echo "<label for='rtype'>Select a rtype</label>";
$sql2 = "SELECT rtype FROM room_details WHERE bname IN($bnames)";
$result2 = mysqli_query($conn,$sql2);
echo "<select name='rtype'>";
while ($row2 = mysqli_fetch_array($result2)){
echo "<option value='". $row2['rtype'] ."'>".$row2['rtype'] ."</option>";
}
echo "</select>";
Don't forget to escape the $bnames variable with the htmlspecialchars function if needed to avoid sql injections.
mysqli_connect_errno() - Returns the error code from last connect call
mysqli_connect_error() - Returns a string description of the last connect error
mysqli_errno() - Returns the error code for the most recent function call
mysqli_sqlstate() - Returns the SQLSTATE error from previous MySQL operation
For more help use this link: http://php.net/manual/en/mysqli.error.php
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 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>