I want a search page with five fields from the MYSQL database shown in individual drop down boxes. I have a basic drop down, adapted from one of the other answers here which I have reproduced five times for each of the fields.
$sql = "SELECT Country FROM engravers";
$result = mysql_query($sql);
echo "<select name\\='Country'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Country'] . "'>" . $row['Country'] . "</option>";
}
echo "</select>";
Repeating with obvious changes gives me five neat little drop down boxes that all work.
I want all of the boxes to be interactive so each box will have a default of "all" unless clicked. That means a user could click on a country and a year and get only the records that fit both criteria.
I want a single submit button to handle them all.
It is simple.
echo "<select name='Country'>";
echo "<option value=''>All</option>";
To get the submit button to submit all of them, just put them all in the same form.
(How you handle the '' option in the search depends on the code that processes the form data)
Related
I'm trying to make an automated absent management software for an academic institute. Being just a rookie i'm stuck at this point. I want the name of a teacher to not appear in the drop down lists against the remaining absent teachers for a particular period once he has been selected to substitute for a staff. This I want without hitting the final submit button in the end. I.e.- before actually storing into actual database.
The name Sujata Das shouldn't appear for Aditi Bhatia for period 3.
Here's the code that I have used to populate the drop down lists..
//------------------FOLLOWING MODULE LISTS DOWN THE NAME OF THE TEACHERS WHO ARE PRESENT AS WELL AS FREE FOR A PARTICULAR PERIOD OF THE ABSENT TEACHER----------------
$a=1;
$r5 = mysql_query("SELECT class FROM timetable WHERE empno={$row['empno']} and period=$a");
while($r6=mysql_fetch_array($r5,MYSQL_ASSOC))
{
if($r6['class']!=0)
{
echo "<td>";
echo "<select name='name' id='name'>";
echo "<option selected disabled hidden value=''></option>";
$r5=mysql_query("select m.name,m.empno,t.empno, t.attend,t.date,s.empno,s.period,s.class from master m,tattend t,timetable s where (m.empno=t.empno and m.empno=s.empno and t.attend=0 and t.date='$d' and s.period=$a and s.class=0)");
while($r6=mysql_fetch_array($r5,MYSQL_ASSOC))
echo "<option value='" . $r6['name'] . "'>" . $r6['name'] . "</option>";
echo "</select>";
echo "</td>";
}
else echo "<td></td>";
++$a;
$r5 =mysql_query("SELECT class FROM timetable WHERE empno={$row['empno']} and period=$a");
}
echo "</tr><tr></tr>";
I'm cobbling together a dropdown list that I would like to display the '[ve_venue]", "[ve_town]' from a MySQL query and, upon selection set a variable that I can use to pass the ve_ID on to an update query that adds a venue ID number to a separate table as a lookup key.
So far I've got some code that I've pieced together from various places and I can get it to display the town in a dropdown - I just need to add the venue field to the dropdown so I get "venue, town" in the list and I also need to be able to pass the ve_ID to a variable, say, $ve_ID so I can call it in some separate code (that will be on the same page in a separate include).
Here's what I've got so far....
<?
include('login_admin_sucess.php');
// Connects to your Database
include '../connect_include.php';
$query = "SELECT ve_ID, ve_venue, ve_town FROM `co_venues` ORDER BY ve_ID ";
$result = mysql_query($query);
while($r=mysql_fetch_array($result))
{
$ve_venue = $r['ve_venue'];
$result_array[$ve_venue][] = $r['ve_town'];
}
echo "<select name='x'>";
foreach($result_array as $v_venue => $value)
{
foreach($value as $title) {
echo "<option value='" . $v_venue . "'>" . $title . "</option>";
}
}
echo "</select>";
?>
I realise that mysql_ is deprecated...I'll work on that once I've got everything functioning.
You can concat the id and venue. For example:
$ve_venue = $r['ve_venue'] . "|" . $r['ve_ID'];
When you use the variable make a split with charapter "|" with preg_split function.
I need to have a selection box display options that are based off of the selection from the drop down box right above it. Once the user selects the Car Make, then I want the Car Models of the car make to be options to be selected.
I have been able to get the car makes options to be displayed from my mysql data base, but now I need the car models of only that make. My data base has two collumns, one for the Make and one for the Model.
The top section of PHP is the way i get the make from a seperate database, and the bottom is my attempt to get the model from a database with makes and models of all cars, but it displays hundreds of models, instead of just the few I want. I heard that AJAX or javascript can automatically upload the results, which would be nice. Any help is great. thanks!
</div>
<?php
mysql_connect('localhost', '*****', '******');
mysql_select_db('*************');
$sql = "SELECT Make FROM CarMakes";
$result = mysql_query($sql);
echo "<select name='carmake3'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Make'] . "'>" . $row['Make'] . "</option>";
}
echo "</select>";
?>
<?php
mysql_connect('localhost', '******', '**********');
mysql_select_db('*************');
$sql = "SELECT Model FROM myTable";
$result = mysql_query($sql);
echo "<select class='modelbox' name='carmodel3'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Model'] . "'>" . $row['Model'] . "</option>";
}
echo "</select>";
?>
<input type="text" maxlength="4" name="car3year" placeholder="year" class="WriteInBox"/>
<input type="text" maxlength="6" name="car3miles" placeholder="miles" class="WriteInBox"/>
</div>
Have you ever heard of JQuery. If not, it time for some education. Among a host of other things, JQuery makes it fairly easy to simpllify your AJAX calls -- Best time I ever invested in web development was learning JQuery. See http://api.jquery.com/jQuery.ajax/ for the JQuery docs for the AJAX method. There are some simple usage examples at the bottom of the page. There are also plugins that handle cascading dropdowns lists with simple code, like this one http://jquery-plugins.net/jquery-cascading-dropdown-plugin
Once you start using JQuery, you will discover the hardest thing is getting good lists of car makes and models -- hint they vary by model year too.
I am required to build a website with a makeshift Cart... I have a select box that shows a product name and 1 box that i want to show the product price (all he information is stored on myPHP)
Is there a way to link/connect the 2 boxes together, so when a user selects the product, the other box will populate with the price? All i can get at the moment is all of the information into the select box....this is doing my tree in.
As you can see the price is in the drop down box but i want it to populate in the box below.
Any help would be appreciated.
the code i am using at the moment is...
$sql="SELECT * FROM tblproducts";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
echo "<select name='product'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['productName'] . "'>" . $row['productName'] . " £" . $row['productPrice'] ."</option>";
}
echo "</select>";
I know i have selected all with dropdown box... and there is nothing that points to the empty text box.. this is because I am unsure how to link / point to it.
This can be done using an ajax call:
call a function or file on onchange event of first dropdown. pass the selected value value of first dropdown to that function or file
then in that function or file select options based on that value, and on success populate those options in second dropdown.
You can do this by loading prices to a javascript. Use onchange event for first block and populate the price of another.
I have a PHP dropdown of a list of groupnames (together with id, so it can be updated). In this FORM page you can change the groupname specified for an item by choosing possibilities from the dropdown coming out from the database. My code below works, but there must be a better way, because I get the first field as the currently set, and then all the possibilities, so I get this record twice.
Example:
- Keyboard (Currently set)
- Speakers (Possible to choose, straight from DBS)
- Midi Controllers (Possible to choose, straight from DBS)
- Keyboard (Possible to choose, straight from DBS)
- Drum set (Possible to choose, straight from DBS)
As you see I get the currently set record again.
My code:
echo "<select name='itemgroupid'>";
// CHOOSE CURRENT SET RECORD AS SELECTED ITEM
echo "<option value='" . $itemgroupid . "'>";
$selected="
SELECT item.itemid, itemgroup.itemgroupname, itemgroup.itemgroupid
FROM item, itemgroup
WHERE item.itemid=$itemid";
$selectedresult=mysql_query($query) or die("query fout " . mysql_error() );
while($record=mysql_fetch_array($selectedresult) ) {
echo "" . $itemgroupname . "</option>";
}
// QUERY TO SHOW ALL POSSIBLE CHOOSABLE RECORDS FROM DATABASE
$itemgroupquery="SELECT itemgroupname,itemgroupid FROM itemgroup";
$itemgroupqueryresult = mysql_query ($itemgroupquery);
while($nt=mysql_fetch_array($itemgroupqueryresult)){
echo "<option value=$nt[itemgroupid]>$nt[itemgroupname]</option>";
}
echo "</select>";
There are 2 ways to achieve what you're looking for:
1) To show the selected item at the top of the dropdown
echo "<select name='itemgroupid'>";
// CHOOSE CURRENT SET RECORD AS SELECTED ITEM
echo "<option value='" . $itemgroupid . "'>";
$selected="
SELECT item.itemid, itemgroup.itemgroupname, itemgroup.itemgroupid
FROM item, itemgroup
WHERE item.itemid=$itemid";
$selectedresult=mysql_query($query) or die("query fout " . mysql_error() );
while($record=mysql_fetch_array($selectedresult) ) {
echo "" . $itemgroupname . "</option>";
}
// QUERY TO SHOW ALL POSSIBLE CHOOSABLE RECORDS FROM DATABASE
$itemgroupquery="SELECT itemgroupname,itemgroupid FROM itemgroup WHERE item.itemid != $itemid";
$itemgroupqueryresult = mysql_query ($itemgroupquery);
while($nt=mysql_fetch_array($itemgroupqueryresult)){
echo "<option value=$nt[itemgroupid]>$nt[itemgroupname]</option>";
}
echo "</select>";
2) Show the selected item in it natural place
echo "<select name='itemgroupid'>";
// QUERY TO SHOW ALL POSSIBLE CHOOSABLE RECORDS FROM DATABASE
$itemgroupquery="SELECT itemgroupname,itemgroupid FROM itemgroup";
$itemgroupqueryresult = mysql_query ($itemgroupquery);
while($nt=mysql_fetch_array($itemgroupqueryresult)){
echo "<option value=$nt[itemgroupid]";
if( $itemid == $nt['itemgroupid'] ) echo ' selected="selected"';
echo ">$nt[itemgroupname]</option>";
}
echo "</select>";
HTH
OK
In your code.
rather than output your selected value at the top, do it the proper way :)
Select your current item (make a note of the itemgroupid for example)
then in your output
while($nt=mysql_fetch_array($itemgroupqueryresult)){
echo "<option ";
if ($savedid==$nt[itemgroupid]) echo "selected ";
echo "$nt[itemgroupid]>$nt[itemgroupname]</option>";
}
echo "</select>";
This will produce with $savedid=1
<option value=0>group 0</option>
<option selected value=1>group 1</option>
<option value=2>group 2</option>
Add the default selected record to a empty array first like
toDisplay = array('selected_record');
Then, get the data from the database using your sql and append it to this array.
Later run a array_unique on it and finally using a loop create the html output string, in the same way you are doing it now.