How to Get Two option value by 1 select? - php

Please modify this code so that i will get 2 option value from this code
<select name="student_class1" class="input-xlarge" >
<option value="null">--Select Class---</option>
<?php $sel_service = "select * from all_services where school_id='$school_id'";
$sel_service= mysql_query($sel_service);
while($display_class= mysql_fetch_assoc($sel_service))
{ ?>
<option value="<?php echo $display_class['sub_cat_id']; ?>"><?php echo ucfirst($display_class['sub_cat_name']); ?></option>
<?php } ?>
student_class1 giving me value sub_cat_id
i want
student_class2 will give me sub_cat_name
iwant both values by one select
plz modify it
i already spent my whole sunday on this problem

something like?
<form action="" method="get" accept-charset="utf-8">
<select name="student_class1" class="input-xlarge" >
<?php
$sel_service = "select * from all_services where school_id='$school_id'";
$sel_service= mysql_query($sel_service);
while ($row = mysql_fetch_assoc($sel_service)) {
?>
<option value="null">--Select Class---</option>
<option value="<?php echo $row['sub_cat_id']; ?>"></option>
<option value="<?php echo $row['sub_cat_name']; ?>"></option>
<?php
}
?>
</select>
</form>

Related

how to get the data on script and load it in query

Why can't I get the value of the element? sorry I'm new at coding and trying to learn
<script>
function getdll() {
document.getElementById('lblmess').innerHTML =
(formid.listid[formid.listid.selectedIndex].value)
$element = document.getElementById("lblmess");
console.log($element.innerHTML)
}
</script>
<form name="formid">
<select class="custom-select" name="listid" onchange="getdll()">
<option value="0"></option>
<?php
$hall_qry = $conn->query("SELECT * FROM `office_hall` WHERE o_id !=0 order by `office_name` asc");
while ($row = $hall_qry->fetch_assoc()) : ?>
<option value="<?php echo $row['o_id'] ?>"><?php echo $row['office_name'] ?></option>
<?php
endwhile;
?>
</select>
<br><br>
<select class="custom-select">
<?php
$hall_qry = $conn->query("SELECT * FROM `assembly_hall` WHERE o_id = '$element' order by `room_name` asc");
while ($row = $hall_qry->fetch_assoc()) : ?>
<option value="<?php echo $row['id'] ?>"><?php echo $row['room_name'] ?></option>
<?php
endwhile;
?>
</select>
<label id="lblmess"></label>
</form>
this is where I use this code sorry if my coding id is like that .............................................................
Try:
onchange="getdll(this.value)"
THEN in your script, put a parameter
function getdll(val){
alert(val);
}
Should be able to get the value you selected

How to update a dropdown value in codeigniter

This i my View code:
<form role="form" action="<?php echo base_url() ?>add_customer" method="post">
<select class="form-control" id="customer_id" name="customer_id">
<?php foreach ( $customer as $cust ){?>
<option value="<?php echo $datas[0]->customer_id; ?>"<?php if($cust->customer_id==$datas[0]->customer_id) echo 'selected="selected"'; ?>> <?php echo $cust->customer_id; ?></option>
<?php }?>
</select>
</form>
For Eg: Dropdown Value contains 1,2,3,4 actually selected value is 2 display in that field correctly. Now, I want to update the dropdown value to 4
How can I do this? Please help..
Hope this will help you :
Change values from value="<?php echo $datas[0]->customer_id; ?>" to this value="<?=$cust->customer_id;?>"
<select class="form-control" id="customer_id" name="customer_id">
<?php foreach ( $customer as $cust ){?>
<option value="<?=$cust->customer_id;?>" <?php if($cust->customer_id == $datas[0]->customer_id) echo 'selected="selected"'; ?> > <?php echo $cust->customer_id; ?></option>
<?php }?>
</select>

avoiding the display of dropdown value twice in edit

While editing the record from database, i display already selected value and option to select other values too. But i want to avoid already selected value to display twice in dropdown. Not getting how to do it
here is my code
<label class="control-label">Sales Area</label>
<?php
$sql5 = "SELECT * FROM sales_area ORDER BY name";
$query5 = mysqli_query($con, $sql5);
?>
<select name="area" class="form-control" required>
<option value="<?php echo $row['sales_area']; ?>"><?php echo $row['areaname']; ?></option>
<?php while ($rs5 = mysqli_fetch_array($query5)) { ?>
<option value="<?php echo $rs5["id"]; ?>"><?php echo $rs5["name"]; ?></option>
<?php } ?>
</select>
in $row['sales_area'], data already present in database, this should not display again.
haven't tested it, but should be something like this:
<select name="area" class="form-control" required>
<?php while ($rs5 = mysqli_fetch_array($query5)) { ?>
<option value="<?php echo $rs5["id"]; ?>" <?php if($rs5["id"] == $row['sales_area'] ) { echo "selected"; } ?> ><?php echo $rs5["name"]; ?>
</option>
<?php } ?>
</select>

How to Add scroll bar to html autocomplete datalist element?

Here is my PHP Code, I am trying to add a scroll bar to my autocomplete search, I have retrieved data from database and wanted to add a scroll bar.:
<?php
include('connection.php');
$result1 = mysql_query("select * from legal_pashto");
$result2 = mysql_query("select * from legal_dari");
$result3 = mysql_query("select * from pashto_pashto");
$result4 = mysql_query("select * from dari_pashto");
?>
<datalist id="words">
<?php while($row = mysql_fetch_assoc($result1)){?>
<option value="<?php print $row['english_word']; ?>
<option value="<?php print $row['pashto_word']; ?>
<option value="<?php print $row['pashto_word1']; ?>
<option value="<?php print $row['pashto_word2']; ?>
<option value="<?php print $row['pashto_word3']; ?>
<option value="<?php print $row['pashto_word4']; ?>
<?php }?>
<?php while($row2 = mysql_fetch_assoc($result2)){?>
<option value="<?php print $row2['english_word']; ?>
<option value="<?php print $row2['dari_word']; ?>
<option value="<?php print $row2['dari_word1']; ?>
<option value="<?php print $row2['dari_word2']; ?>
<option value="<?php print $row2['dari_word3']; ?>
<option value="<?php print $row2['dari_word4']; ?>
<?php }?>
<?php while($row3 = mysql_fetch_assoc($result3)){?>
<option value="<?php print $row3['pashto_word']; ?>
<option value="<?php print $row3['pashto_meaning']; ?>
<option value="<?php print $row3['pashto_meaning1']; ?>
<option value="<?php print $row3['pashto_meaning2']; ?>
<option value="<?php print $row3['pashto_meaning3']; ?>
<option value="<?php print $row3['pashto_meaning4']; ?>
<?php }?>
<?php while($row4 = mysql_fetch_assoc($result4)){?>
<option value="<?php print $row4['dariword']; ?>
<option value="<?php print $row4['darimeaning']; ?>
<option value="<?php print $row4['darimeaning1']; ?>
<option value="<?php print $row4['darimeaning2']; ?>
<option value="<?php print $row4['darimeaning3']; ?>
<option value="<?php print $row4['darimeaning4']; ?>
<?php }?>
</datalist>
I am not very good when it comes to html but in my opinion adding your PHP code may help other help you. Just saying.

PHP dropdown populated from database

I need to pull down a column of color codes for a color picker site I'm making but it won't work:
<select name="select" id="dropdown">
<option id="0">-- Select Color --</option>
<?php
$getColors = mysql_query("SELECT * FROM color_codes");
while($list = mysql_fetch_array($getColors)){
?>
<option id="<?php echo $list ['colorID']; ?>">
<?php echo $list['color_code'] ?></option>
<?php } ?>
</select>
Any ideas?
just did a couple of changes to your code and it worked for me, Hope it works for you.
<?php
$mysqli= new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME) or die(mysqli_connect_error());
$sql="select * from test";
$result=$mysqli->query($sql);
?>
<select name="select" id="dropdown">
<option id="0">-- Select Color --</option>
<?php
while($list = $result->fetch_array(MYSQLI_ASSOC)){
?>
<option id="<?php echo $list['id']; ?>">
<?php echo $list['name'] ?></option>
<?php } ?>
</select>

Categories