I am trying to get a dropdown list to populate. I have two tables, a registration table and a studentclasses table. I am looking to populate the dropdown list from the class table, as a field entry in the registration table. My code is as follows:
<p>Class: <select name="classID">
<?php $classlist_sql="SELECT * FROM studentclasses";
$classlist_qry=mysqli_query($dbconnect, $classlist_sql);
$classlist_rs=mysqli_fetch_assoc($classlist_qry);
do { ?>
<option value="<?php echo $classlist_rs['classID']; ?>"
<?php
if($classlist_rs['classID']==$_SESSION['signuptest']['classID']) {
echo "selected=selected";
}
?>
><?php echo $classlist_rs['classcode']; ?></option>
<?php } while ($classlist_rs=mysqli_fetch_assoc($classlist_qry));
?></select>
</p>
My Studentclasses table has the fields classID and classcode, and I am wanting the classcode to appear in the drop down.
Any help would be greatly appreciated.
Related
I have a function having two dropdown list and one submit button, the user must choose a value from dropdown list A and a value from dropdown list B so he can submit them.
I knew that I need to have an attribute in the value section as follows
<select name="students" id="students">
<?php
while($data = mysqli_fetch_array($selectstudent1)) {
$name=$data['name'];
$idname =$data['user_id_student'];
?>
<option name="studentdd" value="<?php echo $idname; ?>"><?php
echo $name; ?></option>
<?php } ?>
</select>
and the second dropdown list here
<select name="groups" id="groups">
<?php
while($data1 = mysqli_fetch_array($selectgroup1)) {
$groupschoose = $data1['group_number']; ?>
<option name="nogroup" value="<?php echo $groupschoose; ?>">
<?php echo $groupschoose; ?></option>
<?php }//while ?>
</select>
so, i need to get the "php echo $idname" (student id) from A dropdown list
and "php echo $groupschoose; " (group id) form drop downlist B
so I tried this PHP code as follows:
<?php
if(isset($_POST['addmember'])){
//addmember is id for dropdownlists form
$groupnum= $_POST['nogroup'];
$stuid=$_POST['studentdd'];
echo $groupnum;
echo $stuid ;
$sq="SELECT user_id_student FROM student WHERE
user_id_student=$stuid ";
$sq1 = mysqli_query($con,$sq);
while ($sq2 = mysqli_fetch_array($sq1)) {
$tes = $sq2['user_id_student'];
if( $tes == $stuid){
$sqlmem="UPDATE student
set group_id= $groupnum
WHERE user_id_student=$stuid";
$resultmem = mysqli_query($con,$sqlmem);}
}
}
?>
But it won't work, and I'm not sure where is the missing section
I hope my Q is clear and I'm sorry if it's little bit long, but i'm looking for your help, thank you!!
I've spent more than 48hrs trying to solve the following problem to no avail. I want to use datatable in php to update record. I am able to display record based on the user selected, However, some of the inputs are <Select>.
The following code populates the options but I'm getting
Undefined Index error
<td><select name="class_assigned['<?php echo $id; ?>']" class="form-control
class_assigned"><option value="<?php echo $class_assigned; ?>"><?php echo
$class_assigned; ?>
</option>
<?php
$class_sql = "SELECT Class_Name FROM tbl_classes WHERE Class_Name !=
'$class_assigned'";
$class_result = $conn->query($class_sql);
if ($class_result->num_rows > 0) {
while($row = $class_result->fetch_assoc()) {
$class_name = $row['Class_Name'];
?>
<option value="<?php echo $class_name; ?>"><?php echo $class_name; ?>
</option>
<?php }} ?>
</select>
</td>
While the following code populates the Current Class_Name but I couldn't make other options appear:
<td><?php echo '<select name="class_assigned['.$row["id"].']" class="form-control"><option value="'.$class_assigned.'">'.$class_assigned.'</option></select>'; ?></td>
What I want:
Let's say the table displays SS 1A, and the user wants to update to SS 2A. I want the Options in the dropdown to display all classes available in tbl_classes.
Please have in mind that the table can display multiple rows at a time (Array).
Thank you for your help.
<select name="city[]" id="CitySD" class="select required" multiple>
<option value=""><?php echo $this->Lang["SEL_COUNTRY"]; ?></option>
<?php
foreach ($this->all_city_list as $c)
{
?>
<option <?php
if (isset($this->userPost['city']))
{
if ($c->city_id == $this->userPost['city'])
{
?> selected <?php
}
}
?> title="<?php echo $c->city_name; ?>"value="<?php echo $c->city_id; ?>">
<?php echo $c->city_name; ?>
</option>
<?php } ?>
</select>
Above is my city drop down field in registration page,if user select country means then only the city filed gets active and its display city based on user selection country.
I want to display cities in the city drop down with individual checkbox option for all cities and select all option check box,the user can click select all means it will select all cities and deselect means it will deselect all cities and user can also select random cities.
please anyone can help me!
I would like to display the result which I have selected based on the drop down list. This is my drop down list code which is retrieved from the finish_product under bom table (calculate.php)
<tr>
Select product:
<select class="itemTypes">
<?php
while ($row1 = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $row1['finish_product']; ?>">
<?php echo $row1['finish_product']; ?>
</option>
<?php } ?></select>
<br/><br/>
</tr>
For example, under the drop down list I selected 'Table', how do I display the result in doCalculate.php?
Right now I just hard code Table which is not feasible. Anyone to help me out?
There are many, many ways which you could accomplish your goal. I would suggest using a JavaSctipt "onchange" event, detect the selected option, and then update the DOM with its contents.
I am creating a form where the users will have to select the country from the drop down list. as soon as they selects it should activate another drop down list where it should show the states belonging to the country and hence it should process the value from country Id of element. and as soon as the user selects the states another drop down list should activate listing the cities belonging to that particular states, and hence so on to areas.
for that i have written the php and html code like this.
Select Countries : <select name="countries"><br/>
<?php
foreach($property->getAllCountries() as $countries)
{
?>
<option value="<?php echo $countries['id']; ?>"><?php echo $countries['name']; ?></option>
<? } ?>
</select><br/>
Select State : <select name="state">
<?php
foreach($property->getStatesFromCountryId($countryId) as $states)
{
?>
<option value="<?php echo $states['id']; ?>"><?php echo $states['name']; ?></option>
<? } ?>
</select>
the javascript should automatically insert $countryId from and populate the states after the user selects it.
i am noob at javascript i would appreciate if someone could guide me how to achieve this?
thank you.
sorry for bad english.
you should add onchange="showstates()" to select countries and a div to add states of country to it
function showstates()
{
var country=document.getElemtById("countries").value;
if (country=="anywhere")
{
document.getElemtById("statesofcountries").innerHTML='<div>"states list"</div>';
}
}
check this link
You can always google it up:
http://roshanbh.com.np/2007/12/change-dropdown-list-options-values-from-database-with-ajax-and-php.html