i am developing a website for meeting schedule.the user which was currently logged in need to send request to the guests.the names of the guests are provided in the user table in database along with the host.so when i try to fetch the names of all the user expect that of the host only the host's name is displayed in the list menu.my code is as follows
<?php
include("db.php");
$q=mysql_query("select * from user where name='$name'");
while($r=mysql_fetch_array($q))
{
$uid=$r['uid'];
?>
<select name="">
<option name="">geust name</option>
<?php
echo'<option name="">'.$name.'</option>';
?>
</select>
<?php
}?>
i want to list out the guest names in the option other than that of the host.but i dont know how to display it
Try this:
<?php
include("db.php");
$q=mysql_query("select * from user where name='$name'");
?>
<select name="sample">
<option value="<?php echo $r['guestname']; ?>">geust name</option>
<?php
while($r=mysql_fetch_array($q))
?>
<option value="<?php echo $r['name']; ?>"><?php echo $name; ?></option>;
<?php
}
?>
</select>
In your above example you are creating a new select element each Time you loop through results. you are using $name as option value. $name is the value of your search criteria. You want to use $r['name']. Witherwind's answer will get you what you asked. The only thing you need to change is the first option outside loop should be blank.
Related
Currently setting up a form for users to select aircraft information from. Currently, the form allows users to select an airplane and in return when the form is submitted it passes the value"aircraft type" to an API. Due to this, I cannot set the values to be the registration of the airplanes so have put this into the ID for now (open to suggestions).
<select name="type" id="plane-list">
<option selected="selected">Choose one</option>
<?php
foreach($allaircraft as $item){
?>
<option id="<?php echo $item->registration; ?>" value="<?php echo $item->icao; ?>"><?php echo $item->name; ?> - <?php echo $item->registration; ?></option>
<?php
}
?>
</select>
As you can from above these are all dynamic values which change over time so hard coding the options are not possible.
So summed up I need to pull the ID or $item->registration; instead of ICAO code. This then needs to be set as a variable so that I can call a function with this code.
Let me know if you need me to clear up anything. Don't normally questions on here so be nice.
I need to make one of the form into read only based on user's division
here's my form in my view:
<select class="form-control" name="division" id="division">
<option selected="selected" disabled="disabled" >-Choose-</option>
<option selected="selected" value="all">All</option>
<?php
if($query->num_rows()) {
foreach($query->result() as $row):
?>
<option value="<?php echo $row->id_division?>">
<?php echo $row->name_division;?>
</option>
<?php
endforeach;
}
?>
</select>
Is there any way to make it read only based on the user's id_division? So once they click submit or something this will also input their own id_division
I guess from your question that there are more than one $id_division, and more than one <option> in the select dropdown. In that one $id_division belongs to the current user.
While submitting form, value of this current user's $id_division only need to pass. In other words, by default the dropdown value should be automatically set for the option which belongs to the current user.
For that case you have to check each &id_division in the foreach loop whether its equal to the id_division of current user. And add the selected attribute dynamically to the <option> if it equals.
for that,
<?php
if($query->num_rows()) {
foreach($query->result() as $row):
if($id_division==[id_division of current user]){//You have to replace [id_division of current user] with variable that you keep current user id_division data.
$selected='selected';
}else{
$selected='';
}
?>
<option value="<?php echo $row->id_division?>" <?php echo $selected;?>>
<?php echo $row->name_division;?>
</option>
<?php
endforeach;
}
I have a dropdown box where the data is coming from my database. I want to send the selected drop-down item to the controller action method. And then I will send these values to the model to do the further works. Here, the problem is I have two database values in a single item of drop-down box. And, I am not figuring out how to send those two the method. Here is my code given below,
<select name='select'>
<option selected disabled>Choose Stations</option>
<?php foreach ($get_stations as $get_stations_item): ?>
<option>Station <?php echo $get_stations_item['sourcestationid']; ?> - Station <?php echo $get_stations_item['destinationstationid']; ?></option>
<?php endforeach; ?>
</select>
From this dropdown items, I want to send the sourcestationid and destinationstationid separately as 2 parameters to my controller action method. Here is my controller code though this is not correct way I think,
function getdata(){
$iotdata['test'] = $this->input->post('select2');
//rest of the code according to the source and destination id item
}
Thanks in advance.
You haven't kept the variable inside option's value tag.
<select name='select'>
<option selected disabled>Choose Stations</option>
<?php foreach ($get_stations as $get_stations_item): ?>
<option value="<?php echo $get_stations_item['sourcestationid'].','.$get_stations_item['destinationstationid']; ?>">Station <?php echo $get_stations_item['sourcestationid']; ?> - Station <?php echo $get_stations_item['destinationstationid']; ?></option>
<?php endforeach; ?>
</select>
Also here at PHP end, you can explode the string into an array and store it further into db.
<?php
$select = explode(',', $select)
print_r($select); // this will have your two values
?>
Thanks #BitsPlease for our suggestion. Your idea is working. But I need to do a small change to get it instantly. My select tag needs to be under form tag to get them without reloading the page again. Here is my view,
<form method="post" accept-charset="utf-8" action="<?php echo site_url("controller/action"); ?>">
<select name='select' onchange="this.form.submit()">
<option selected disabled>Choose Stations</option>
<?php foreach ($get_stations as $get_stations_item): ?>
<option value="<?php echo $get_stations_item['sourcestationid'].','.$get_stations_item['destinationstationidr']; ?>">Station <?php echo $get_stations_item['sourcestationid']; ?> - Station <?php echo $get_stations_item['destinationstationidr']; ?></option>
<?php endforeach; ?>
</select>
</form>
Here is the php code,
$select = explode(',', $this->input->post('select'));
print_r($select)
<?php
$sql="select software from software_table";
$qry=mysql_query($sql);
$count=mysql_num_rows($qry);
$row=mysql_fetch_array($qry);
$data=['software_name'];
?>
<?php
for($i=0; $i<=count($data); $i++){
?>
<select name="software_name">
<option vale="<?php echo $data[$i]?>">$data</option>
}
?>
`I dont know if this is possible, but what I want to happen is that, when I add new software from software_table. My drop-down menu for software will get its option value from the database to become updated. I am thinking to use For-Loop for this, but I dont know how to start or is it really possible.
example.
in my drop-down menu. i have 3 option value.
1.MS OFFICE
2.AUTODESK
3.PRIMAVERA
and then I add another software from the database which is WINDOWS 8.
I want my drop-down menu to have those 4 value.
Try to use the following code -
$sql="select software from software_table";
$qry=mysql_query($sql); ?>
<select name="software_name">
<?php while($row=mysql_fetch_array($qry)) {
$data=$row['software_name']; ?>
<option vale="<?php echo $data; ?>"><?php echo $data; ?></option>
<?php }
?>
</select>
<select name="software_name">
<?php
$sql="select software from software_table";
$qry=mysql_query($sql);
while ($row=mysql_fetch_array($qry))
{
// In your case, each row contains only one value: $row[0] = the value of software field
echo "<option vale=\"$row[0]\">$row[0]</option>";
}
?>
</select>
This will generate the HTML code as:
<select name="software_name">
<option vale="MS OFFICE">MS OFFICE</option>
<option vale="AUTODESK">AUTODESK</option>
<option vale="PRIMAVERA">PRIMAVERA</option>
</select>
currently i am working on a system. here i have a drop down list and its values are populating from database. now what i need is when ever some one selects a record from the list the selected value should be get stored in a session variable which ll get displayed in an another page. can we do so. i am coding in php.
my code is:
<td align="center">
<?php
$sql_dep=" Select * from places_tbl";
$row_dep = $db->Execute($sql_dep);
$total_dep = $row_dep->RecordCount();
?>
<select name="place" class="txtbx08" id="place">
<option value="">--Please Select City--</option>
<?php if($total_dep>0) {
while(!$row_dep->EOF)
{
?>
<option value="<?php echo $row_dep->fields["place_id"];?>">
<?php echo ucfirst($row_dep->fields["place_name"]); ?>
</option>
<?php
$row_dep->MoveNext();
}}
?>
</select></td>
I'm not sure how you're retrieving the selected value (assumingly through POST), but the normal procedure would be:
session_start();
$_SESSION['place'] = $_POST['place'];