how to get previous selected value in a select list - ajax

I have a form in that we have a drop down list ( apple, gova, lemon .. ) each one has some counter like apple =5, gova=3, lemon=6. If i select apple at first then count of apple becomes apple=4, suppose i want to change my selection from drop down list lemon, now lemon should become 5 and apple=5. how to do that ?
code :
<select>
<option>apple </option>
<option>gova </option>
<option>lemon</option>
..
..
</select>
note : these list of fruits im getting from a table called fruits of mysql.
table schema : fruit_table
apple gova lemon ... etc
5 3 6 .....
in advance,thanks for your comments and solutions that you have given.

Decrement the value only when the user submits the form. Not when he changes his select option.
Change the fruit_table schema columns to: fruit_name , count. From your example, it seems column names are fruit names

Related

Oracle Apex dynamic action PL/SQL that will change the values in a select list based on a value passed by another field

So i have a Table Called "Fruit" this table is manually upload with what kind of Fruit the users like. But we know that we have different colored "Fruit" these colors are not on the table.
So i have created a form for the user and want to create a dynamic select list based on the "Fruit"
Form:
Name: Bob
Age: 45
Fruit: Apple
What color:(Select List based of Fruit) Red,Green,white
Now i have 12 fruit option on the table and maybe six color i want to use, but i do not want all the colors displayed.
So if the "Fruit" column (based on table) was apple only show Red,Green,white in the select list
if the "Fruit" column (based on table) was banana only show Yellow,Green,Brown in the select list
if the "Fruit" column (based on table) was grape only show Red,Green in the select list.
APEX can do this quite easily. Define the query for the colors so that it only shows the colors appropriate for the fruit item selected. Something like:
select c.color_name, c.color_code
from colors c
join fruit_colors fc on fc.color_code = c.color_code
where fc.fruit_code = :P123_FRUIT_CODE;
(Here P123_FRUIT_CODE is the name of your fruit select list item).
Then set the Cascading LOV Parent Item(s) property of the colors LOV to P123_FRUIT_CODE.
Now, whenever the user changes P123_FRUIT_CODE by selecting a fruit, the colors LOV will be updated to show only the colors available for that fruit.

Count Length and then Count those records.

I am trying to create a view that displays size (char) of LastName and the total number of records whose last name has that size. So far I have:
SELECT LENGTH(LastName) AS Name_Size
FROM Table
ORDER BY Name_Size;
I need to add something like
COUNT(LENGTH(LastName)) AS Students
This is giving me an error. Do I need to add a GROUP BY command? I need the view:
Name_Size Students
3 11
4 24
5 42
SELECT LENGTH(LastName) as Name_Size, COUNT(*) as Students
FROM Table
GROUP BY Name_Size
ORDER BY Name_Size;
You may have to change the group by and order by to LENGTH(LastName) as not all SQL engines let you reference an alias from the select statement in a clause on that same statement.
HTH,
Eric

Sqlite query to determine gender by first name

I have 2 sqlite3 tables :
FND is a Table of names and their likely gender i.e.:
nm,gndr <-column names
Aliyah,F
Moses,M
Peter,M
Members is second table i.e.
Fname,Lname <-column names
DAVID X, BAKER
MARY MIA,MCGEE
TINA HEATHER,JOHNSON
JIM PETER TOM, SANTINO
The members table has first and middle names in the fname column.
I am trying to write a query to list the Members table fnames column, with a generated column indicating gender based on the first word in the fname column.
I tried this but it didn't work:
select m.fname,(select gndr from FND where upper(nm) like m.fname||'%')as gender
from Members m
can anyone correct my sql statement?
... upper(nm) like m.fname||'%'
Let's look at some example values:
nm: 'David'
fname: 'DAVID X'
SQL: 'DAVID' LIKE 'DAVID X%'
This obviously does not match.
You have to reverse the LIKE operands:
m.fname LIKE nm||'%'

HTML Form: Insert id from related table

I'm relatively new to both php and mysql and here's my first question:
I have 3 tables. One as the "main table" and two as basically lists/categories of which I can choose and relate them to my main table. So:
Table 1
id name hobby color
1 Peter 1 2
2 Simon 3 2
3 Lisa 2 3
Table 2 would then be hobbies
id name
1 Swimming
2 Football
3 Piano
Same with table 3 and colors.
id name
1 red
2 blue
3 green
Now, I have managed to "relate" the tables with phpmyadmin, but how can I do the following:
I wanna insert data into the first table. But the thing is, I wanna insert a simple number in hobbies or colors. But within the html form, there should be the text related to the is.
So if i choose 'green'(as a string), it should insert 3 into Table 1.
I hope it's clear what i want :D
Thanks for every help in advance.
Simon
Create your html like this:
<select name="color">
<option value="1">red</option>
<option value="2">blue</option>
</select>
When an user select "blue" the value of input.color is "2". So an end user selects an string/color and you can insert the int/id

Google Spreadsheet Dropdown Filter

I have Google spreadsheet with a list of names in a column. (EX: David, Daniel, John, Cooper).
I made a drop down list of those names. Lets say I two more columns with Age and Birthday.
I want to show the age and birthday column information pertaining to 'David' when I choose 'David' from the drop down list.
A drop down list acting as a 'in spreadsheet filter'.
Any way to do this?
Ive tried the =FILTER() and =UNIQUE() but they don't quite get me what I want. Thanks for the help
Assuming you have the drop down list in cell A1 (of sheet 2) and the columns with data are in sheet1
col A names
col B age
col C birthday
in cell B1 (of sheet2)
=QUERY(Sheet1!A1:C, "Select B, C where A = """&A1&""" ", 1)

Resources