473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Finding New record insertion

65
Hi friends,

I'm creating a table which extract 2 fields from another 2 tables. It's working well.
Whenever a new row inserted into the existing 2 tables it should be updated into the new table. How can I do it?

My create table code is:

Expand|Select|Wrap|Line Numbers
  1. create table exam(select a.username,b.qualification from users a, skill b where a.username=b.username);
If any new row inserted into the skill or users table, it should be reflected on the exam table.

For this i'm writing php script and my logic is,

i fetch the max(ID) from the skill table.
when the ID should be increased, then the new row will be inserted into exam table.

But My question is how do i know when the new row is inserted in the skill table or when will be the ID is increased?

Is my logic right? or any other ideas to do it?

Please show me the proper code.
Help me out......
Mar 14 '08 #1
7 1587
satas
82
But My question is how do i know when the new row is inserted in the skill table or when will be the ID is increased?
You mean, that records in skill/user appear not through PHP? Someone manually inserts them using, for example phpMyAdmin? If no, why can't you write another php-function to insert new record in exam table after skill/user update?

It could be done also via DB triggers, without any php code. Even MySQL has them since 5.X version.
Using them you are able to perform some operations BEFORE or AFTER some ivents. E.g. you can insert new row in exam table AFTER insertion row into skill/user table. Check this to find out more information:
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
Mar 14 '08 #2
yasmine
65
You mean, that records in skill/user appear not through PHP? Someone manually inserts them using, for example phpMyAdmin? If no, why can't you write another php-function to insert new record in exam table after skill/user update?

It could be done also via DB triggers, without any php code. Even MySQL has them since 5.X version.
Using them you are able to perform some operations BEFORE or AFTER some ivents. E.g. you can insert new row in exam table AFTER insertion row into skill/user table. Check this to find out more information:
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
hi
Thanks 4 ur reply.
I didn't understand clearly what u r saying.
Is there anything wrong with my logic?
How can i create trigger for inserting the same values which inserted on another table? Is it possible?
Can you show me those lines?

Expand|Select|Wrap|Line Numbers
  1. create trigger ins_trig after insert on users for each row 
  2. begin
  3. insert into exam values(select username,qualification from users where exam.username!=users.username);
  4. End;
It shows me error.

Thanx n regards
Yas
Mar 14 '08 #3
satas
82
How can i create trigger for inserting the same values which inserted on another table? Is it possible?
Yes it is:
Expand|Select|Wrap|Line Numbers
  1. create trigger ins_trig after insert on users for each row 
  2. begin
  3. insert into exam values(NEW.username,NEW.qualification);
  4. End;
This should work, but i have not tried.

By the way, do you use php in your logic? Or it is only about database?
Mar 14 '08 #4
yasmine
65
Yes it is:
Expand|Select|Wrap|Line Numbers
  1. create trigger ins_trig after insert on users for each row 
  2. begin
  3. insert into exam values(NEW.username,NEW.qualification);
  4. End;
This should work, but i have not tried.

By the way, do you use php in your logic? Or it is only about database?

Thanx again,
Can u tell me what is this 'NEW' keyword refers?
This code doesn't show the fields on users table na?
I want what ever values will be inserted into the users table should be reflect on the exam table.

Help me out.......
Mar 14 '08 #5
satas
82
Thanx again,
Can u tell me what is this 'NEW' keyword refers?
This code doesn't show the fields on users table na?
I want what ever values will be inserted into the users table should be reflect on the exam table.

Help me out.......
In a few words NEW is the last inserted row from table `user`

Read this carefully :
http://dev.mysql.com/doc/refman/5.0/en/using-triggers.html

And after that ask questions.
Mar 14 '08 #6
ronverdonk
4,258 Expert 4TB
This is a MySQL question and does not belong in the PHP forum.
Will be moved.

moderator
Mar 14 '08 #7
yasmine
65
In a few words NEW is the last inserted row from table `user`

Read this carefully :
http://dev.mysql.com/doc/refman/5.0/en/using-triggers.html

And after that ask questions.

Thanks a lot yaar.............

Now I understood.
Mar 14 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Sugapablo | last post by:
Let's say I create a new record in a table like this: mysql_query("INSERT INTO table (col1) VALUES ('example')",$conn); ....that had an auto-incrementing, unique identifying column named "ID"...
17
by: Rick | last post by:
Hi all, Is there a MySQL function to get the first record through a query? I would like to open a page of client records with the first one shown. The other records can be accessed from a...
2
by: Nhat Yen | last post by:
Hi everyone, I tried to upload my database to my web host. Nevertheless as they do not give me enough permission to perform some DTS thus I have to generate script to do it myself. The problem...
10
by: salamol | last post by:
I has a strange question. My company is using a old system with Win NT 4.0 Server + MS SQL 7.0. The system is busy and handle a lot of SELECTs and INSERTs all the time. Sometimes, some...
2
by: Devesh Aggarwal | last post by:
Hi, I have a backup and restore module in my project. The backup uses a typed dataset object (XSD) to get the data from database and creates a xml file as the backup file (using the WriteXml...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
0
by: htmlgeek | last post by:
I'm adding and updating records in an Access .mdb via WWW .asp page. Authored in Dreamweaver 2004 MX. Help is welcome on this one. I have a great set of pages that work fine, but it seems that...
0
by: polocar | last post by:
Hi, I have noticed a strange behaviour of CurrencyManager objects in C# (I use Visual Studio 2005 Professional Edition). Suppose that you have a SQL Server database with 2 tables called "Cities"...
19
by: tkpmep | last post by:
I have an ordered list e.g. x = , and given any positive integer y, I want to determine its appropriate position in the list (i.e the point at which I would have to insert it in order to keep the...
7
by: chowdary | last post by:
I am developing a PHP-mysql database. It is noted that when the browser window is refreshed the data is inserted again in the database. unfortunately there is no unique keys that I can use to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.