I want to make a poll for my website(flash) where I can change the question from time to time. When I put up a new question, question_id in table1 will change (auto increment)
I am trying to make an updatefunction in php to work with amfphp and flash.
I have two tables:
1: Question: question_id, question.
2: Answer: answer_id, answer, question_id
question_id is foreign key in table 2. Can I somehow update question_id in table 2 with the 'most recent or higest' value from question_id in table 1.
I hope you understand my question, I find it very difficult to explain what I am looking for.
Any help is much appreciated, Thank you.
Karla
5 1990 dlite922 1,584
Recognized Expert Top Contributor
I don't understand your question.
If it's a poll, then you provide the question (table1) and the user taking the poll provides records in answer table (table2).
You're program should know which question the user is answering to tie that back to table 1, so all you have to do is make sure you have the most recent question.
Which is easy to do if the latest question has the highest question_id
SQL:
SELECT * FROM question_table ORDER BY question_id DESC LIMIT 1;
Feel free to elaborate more,
Dan
I see I have a long way to go when I can't even explain my problem. I am not even sure I am looking for an UPDATE.
At first my poll worked just fine (I only have one question and you can only answer yes or no). Everytime the user answered yes, the function just inserted yes into the answer table: INSERT INTO answer(answer) VALUES('yes');
The problems started when I wanted to add a new question. To make sure that the new answers only belonged to the new question, I added a foreing key to the answer table: question_id. So now my INSERT must look like this: INSERT INTO answer(answer, question_id) VALUES('yes', some variable question_id that comes from the question table). I don't know how to get that variable into VALUES, that's when I thought I needed an UPDATE instead, but that won't work either.
Does this make any sense at all?
I am totally new to this, but I really want to learn.
Thank you for your time
Karla
@karla007
After a good nights sleep and some more research I found the solution:
INSERT INTO answer (answer, question_id) VALUES ('yes', (SELECT MAX(question_id ) FROM question));
It has taken me two days to find out!
dlite922 1,584
Recognized Expert Top Contributor
that variable should be pushed to the query just like the answer.
So basically the question_id is in a hidden form field along with the answer.
When it gets submitted with answer, you just provided in the VALUES. There is no need for the MAX(question_id )
Ask yourself this. What if you have multiple questions displayed at the same time, how do you know which answer goes to which question?
The solution: submit the question_id with every question's answer.
Hope that makes sense,
Dan
dlite922 1,584
Recognized Expert Top Contributor @karla007
You have hard coded 'yes' into that query? isn't that actually coming from the user? How do you know the user answered 'Yes'? what about "no"?
What if the answer is not yes/no, what if it's A,B,C or a number?
Dan
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Chris Nighswonger |
last post by:
------=_NextPart_000_0013_01C352C0.6B0A6E30
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi All,
Is it possible in MySQL to use UPDATE to update fields in one table =
with
data from another table? For example, the following code seems to be the
answer but fails with a syntax error in MySQL:
|
by: Deja User |
last post by:
This is probably very simple but I can't figure out a way to update
one table from another table.
Here is an example:
------
TABLEA
------
first_name
last_name
|
by: Mike9900 |
last post by:
What is the best way to copy DataRow from one table to another table,
without copying its structure, which means copying only its data.
--
Mike
|
by: thengfen |
last post by:
Hi!
Im having a problem in transfering a set of records from a table to another table. The scenario is when i select combo box (Course taken such as diploma in IT), then the process will automatically save the list of subjects that need to be taken by students into student course info table.. i hv link all the related table together... I had tried a few solution but still cant... Hope somebody can help.... Thanks a lot! :)
|
by: satishkhachane |
last post by:
--------------------------------------------------------------------------------
I want to select one or more columns from one typed datatable and add it to another table . how I can do this ?
Eg :-
table master
it has column masterid , mastername
now i select masterid and assign it to new comlunm.
| |
by: Sakakini |
last post by:
How can I append last entry from one table to another table???
|
by: xoozlez |
last post by:
Hi there,
How do I insert new records from a dbo table to another table?
This is what I have:
1 dbo_company
1 Member (table)
I made a query in dbo_company with the criteria I only want to retrieve out new records from "ceo_email" and "contact_email" column after e.g 25.July.07
|
by: tomash |
last post by:
Hi!
I ve got two tables in Access 2007.
I want to update a field of DataTable from another table, DataSumTable when two of their fields equals.
( the fields : Name and Period)
I tried this sql code:
UPDATE DataTable
|
by: anil2083 |
last post by:
How to migrate the comma separated values from one table to another table?
suppose we have table i.e XYZ and we have comma separated values in few columns i.e( column_name and values are A,B,C,D).Now i have to migrate these comma separated values into new table i.e PQR.
Example:
Table1
column_name1 complexion
values : VF,F,AVG etc..
column_name2 profession
values : TEA,LECT etc...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |