Get data into a jq easy ui combobox using php - php

< input id="cc" class="easyui-combobox" name="dept"
data-options="valueField:'id',textField:'text',url:'get_data.php'">
This is a code used in creating a jquery easyui combobox. Can anyone help me with how to write the php code in get_data.php. That means for example lets say there is a table called DEPT with two colums dep_id and dep_name.I want to diplay dep_name in the combobox and valueField to be dep_id.

I use this all the time, and there is no call to a seperate php file to get the results:
<label for="cc">Name of DDB here</label>
<select id="cc" name="cc" style="width: 300px">
<option value="">--Select ?--</option>
<?php
$query = "SELECT dep_id, dep_name FROM YOUR TABLE HERE ORDER BY dep_name";
$result = $conn->query($query);
while ($row = $result->fetch_assoc()) {
echo '<option value="' . $row['dep_id'] . '" >' . $row['dep_name'] . '</option>';
}
?>
</select>
and all of this goes right where you want your drop down box.

Related

Dependent Drop down list with just php and mysql

I'm trying to create a dependent drop down list.in the code there are two select box one is department other being doctor.so what i want is if i select department 1 only the doctor in dept 1 with be in the option.what can i do?
what i wanted to do was using id ='iddept' from the department block and using it in the doctor's block.
<form class="" action="" method="post">
<select class="" name="deptname">
<?php
$deptsql=mysqli_query($con,"select deptname,deptid from department where status='1'");
while ($row = mysqli_fetch_assoc($deptsql))
{
echo "<option id='iddept' value='" . $row['deptid'] ."'>" . $row['deptname'] ."</option>";
}
?>
</select>
<br><br><br>
<label>select doctor</label>
<select class="" name="doc">
<?php
$dee=$_POST['iddept'];
echo $dee;
$docsql= mysqli_query($con,"SELECT * FROM doctor INNER JOIN department ON department.deptid=doctor.deptid WHERE department.deptid='$dee'");
while ($row = mysqli_fetch_assoc($docsql))
{ echo "<option value='" . $row['name'] ."'>" . $row['name'] ."</option>";
}
?>
</select>
</fieldset>
</form>
is it possible to this with just php and mysql?
Of course you can, having it set up this way. By the way, you can use a fixed id value in a loop operation as the id value must be unique in one html document.
As I get it, when you select a department, you need to submit the form. If so, then you can control what gets shown in the doctors dropdown. You don't even necessarily need to use join between tables, since you already have all information you need in the doctors table. Your second query would look like:
$docsql= mysqli_query($con, "SELECT * FROM doctor WHERE deptid = '$dee'");

Data Not Showing Up From A For Loop

I am making a product recommender in my shopping cart, something similar to when you go to the grocery store and pickup candy as an impulse.
It looks like below. When I click on the dropdown menu, it does not dropdown with the data I am looking for.
I am using the following code that I would think would input this data:
<?php foreach($Fluoros['Fluoro'] as $Fluoro) {
echo $Fluoro['Fluoro'], '<br>';
}
?>
<select title="Add Fluoro To Your Cart" id="<?php echo $Fluoro['Description']; ?>" class="selectpicker white-drop crimp-part" data-width="auto">
<select title="Select Fluoro" id="<?php echo $Fluoros['Product']; ?>" class="selectpicker white-drop crimp-part" data-width="auto">
<?php foreach($Fluoros['Product'] as $Fluoro){
echo '<option ' . 'value = ' . $Fluoro['Fluoro'] . ' </option>';
}
?>
</select> ```
[enter image description here][1]
[1]: https://i.stack.imgur.com/AXygI.png
The data is being pulled in my "Cart " class. The Select statement below works and brings the correct results
```php
public function fluoroCart() {
$getFluoroProducts = $this->_db->query("SELECT i.Part_Number, i.Description
FROM Inventory i
INNER JOIN Product_Details pd on pd.Part_Number = i.Part_Number
WHERE pd.Category_ID = 15");
$fluoroProducts = $this->_db->results();
foreach($fluoroProducts as $Fluoro){
$Flouros [] = array( 'Fluoro'=>$Fluoro->Part_Number, 'Description'=>$Fluoro->Description);
}
}```
In HTML, select option values need to be surrounded by quotes. Also, in addition to indicating a value, you need to put some text between the opening and closing option tags for it to actually show up in the menu.
<select>
<option value="some value">Some Value Text</option>
</select>
You need to modify your PHP like this
echo '<option value = "' . $Fluoro['Fluoro'] . '">'.$Fluoro['Fluoro'].' </option>';

Select from drop-down menu and reload page

I've got a table that populates data from a MYSQL database and populates a drop-down menu from the same database. I have the drop down menu and table just fine, I would like to be able to choose which data I show in the table however.
<select name = 'peer-id' method='post' style = 'position: relative'>
<?php
while ($content = mysql_fetch_array($peer)) {
echo "<option value='" . $content['Peer'] . "'>" . $content['Peer'] . "</option>";
}
$results = mysql_query("SELECT Destination FROM rate ");
?>
</select>
That's what I have for the select box. How can I get the choice from that and save that as a variable and refresh the table data?
I need to clarify that this will change that current data
#Data#Data#Data
#Data#Data#Data
#Data#Data#Data
Then choose drop down choice and I want it to show new data
#Data2#Data2#Data2
#Data2#Data2#Data2
#Data2#Data2#Data2
So it's going to need to load a new page or refresh some how because it's changing via PHP and not javascript.
I think form may be better, for example
<form id="myform" method="post">
<select name = 'peer-id' style = 'position: relative' onchange="change()">
<option value="1">12</option>
<option value="2">15</option>
<option value="3">16</option>
<option value="4">18</option>
</select>
</form>
<script>
function change(){
document.getElementById("myform").submit();
}
</script>
In the above code, whenever you change the value of select, it will post to the backend, then according to the posted value, you can do want you want, to get the peer-id in php, you can use the following code
$peer-id = $_POST['peer-id'];
Hope helps!
apply this code in select tag hope this works
<select onchange="location = this.options[this.selectedIndex].value;" style="text-decoration:none;">
<option value="customers.php"></font></option>
</select>
insted of the static options, you can do it like this :) here you get all the options from the database. Just replace it with the static options
$peer = mysql_query("SELECT Peer FROM rate Group By Peer Where peer = 'variable'");
$result_peer = mysql_query($peer);
if($result_peer){
while($row_peer = mysql_fetch_array($result_peer)){
echo'<option value='.$row_peer['Peer'].'>'.$row_peer['Peer'].'</option>';
}
I agree in using form, and with this you can echo back onto the page with a submit button (code tested):
<form id="myForm" method="POST">
<select name="select" onchange="<?php echo $_SERVER['PHP_SELF'];?>">
<option value="N">No</option>
<option value="Y">Yes</option>
</select>
<input type="submit" name="formSubmit" value="Submit" >
</form>
<?php
if(isset($_POST['formSubmit']) ){
$var = $_POST['select'];
$query = "SELECT * FROM table_name WHERE DesiredField='$var'";
$result = mysql_query($query)
or die(mysql_error());
while($row = mysql_fetch_array($result)){
$var2 = $row['FieldName'];
echo "First field: " . $var2 . "<br>";
// and so on for what you want to echo out
}
}
?>

AJAX + PHP self-generated fields producing blank results

I'm back and this one might be a little tricky but we will find out! :D
Okay I am using php to self populate my select fields so I don't have to continuously update the options when new agents join. I am using ajax (javascript) for this part of the page and I have had no problems with this except with the company select field.
Live site
All my select fields work with out any problems but the Company field which will display nothing only on companies that seem to have "&" in the name. (Two companies still work with "&" in the name)
List of non-functioning Companies:
-Anthem
-Bogart
-Burnham
-Church Insurance
-Fawcett
-JRM
-Kenneth B. Brown
-Newton
-Sam F.
-Sherrill
-Wallace & Turner
PHP Company select code: (The if/else statement in the companies field would ideally be if ($row['Company'] !== NULL) {
echo '<option value="'.$row['Company'].'">'.$row['Company'].'</option>';
} but for some reason it will echo in a blank space in the option dropdown.)
<label for="company">Company</label><br />
<select id="company" name="users" onChange="showUser(this.value)">
<?php include 'login.php';
$result = mysqli_query($con, "SELECT DISTINCT Company FROM `roster` ORDER BY Company ASC;");
echo '<option value="">' . 'Select a Company' .'</option>';
while ($row = mysqli_fetch_array($result)) {
if ($row['Company'] == NULL) {
}
else {
echo '<option value="'.$row['Company'].'">'.$row['Company'].'</option>';
}
}
?>
</select>
PHP for other select fields:
<label for="last">Last Name</label><br />
<select id="last" name="Last_Name" onChange="showUser(this.value)">
<?php include 'login.php';
$result = mysqli_query($con, "SELECT DISTINCT Last_Name FROM `roster` ORDER BY Last_Name ASC;");
echo '<option value="">' . 'Select an Agent' .'</option>';
while ($row = mysqli_fetch_array($result)) {
echo '<option value="'.$row['Last_Name'].'">'.$row['Last_Name'].'</option>';
}
?>
</select>
Any Ideas on this one? If you need to see the process.php page which echos in the results then just ask! Thanks a million to anyone who helps out.
How the HTML looks when populated through php:
<select id="company" name="users" onchange="showUser(this.value)">
<option value="">Select a Company</option><option value="A.R.T. Group">A.R.T. Group</option><option value="ALPHA Benefits">ALPHA Benefits</option>
</select>
I only included a few since 80ish of them is one massive line of html.
You need to urlencode the parameter that is being passed via ajax. The ampersand is telling PHP that $_GET['q'] is complete and a new $_GET variable is starting.
Notice the %26 for the ampersand returns the desired result.
http://healthbenefitsohio.com/process.php?q=Anthem%20Blue%20Cross%20%26%20Blue%20Shield
Your company options should look like this:
echo '<option value="'.urlencode($row['Company']).'">'.$row['Company'].'</option>';
For good measure, I would also encode the display
echo '<option value="'.urlencode($row['Company']).'">'.htmlspecialchars($row['Company'],ENT_QUOTES).'</option>';

PHP To Select From MySQL & Insert Into Drop Down List

I have searched the internet and I just cant seem to get my head around what to do in order to populate my drop down list from my database.
I have a table called users where there are roles such as chairman, secretary and admin.
My code is as follows:
<td>
<span id="spryselect1">
<select name="chairperson" id="chairperson">
</select>
<span class="selectRequiredMsg">You Must Choose A Chairperson For This Meeting</span>
</span>
</td>
How do I populate a drop down list so that it shows all the chairman available?
Something like this should do the trick. You probably need to work on the wrapper function that creates the drop-down but it's a start. If you are not comfortable with mysql_fetch_object() and you are more familiar with arrays then you can user mysql_fetch_array()
<?php
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("select * from mytable");
function sql_to_select ($result) {
$output = '<select name="chairperson" id="chairperson">'
while ($row = mysql_fetch_object($result)) {
$output. = '<option value="' . $row->role_id . '">' . $row->role . '</option>';
$output .= '</select>';
return $output
}
?>
<html>
<body>
<h3>Here will come the select</h3>
<div class="wrap-select">
<?php print sql_to_select($result); ?>
</div>
</body>
</html>
At a very basic level, you need to loop through each result and output an '...' element to the list:
<select name="chairperson" id="chairperson">
<?php
// ... Assumes you already connected to and selected a database
$result = mysql_query('SELECT ...');
foreach (mysql_fetch_assoc($result) as $row) :
?>
<option value="<?= $row->id_column; ?>"><?= $row->column_to_display; ?></option>
<?php
endforeach;
?>
</select>
Obviously, you'll need to replace "id_column" with your primary key or whatever you want to use to uniquely identify the list item, and "column_to_display" should be "name" or "title" or whatever should be displayed in the option.

Categories