Jump to content

Archived

This topic is now archived and is closed to further replies.

abdfahim

How to make Table relation?

Recommended Posts

I am not sure whether it is possible what I m wanting to do. I have two table "tableA" and "tableB". Now I want 2 things ..

1) "columnA1" of "tableA" automatically contains same value as "columnB1" of "tableB". If I change/add anything in "columnB1" of "tableB", it will automatically changed/added in "columnA1" of "tableA".

2)I want "columnA2" of "tableA" = Sum of ("columnB2" of "tableB") all time. "columnB2" is a integer field.

So plz help me. I m very much starter in mysql.

Share this post


Link to post
Share on other sites
The only way to actually do this is using triggers (MySQL 5), but I'm not sure why you want to do this.

Share this post


Link to post
Share on other sites
That is because I want to show the website summery (like total user, online user, post ... etc) on the 1st page of my website. To do this I have to access different database and tables which i afraid may coz delay in loading the page. So what I want is to create an extra table and put the necessary field related to original tables so that I can get all the info by accessing one single table.

Share this post


Link to post
Share on other sites
This different database is where?

Share this post


Link to post
Share on other sites
Ok, the whole situation is -
I have 4 database "userdb","forumdb","newsdb","profiledb". [b]All databases are in the same server[/b], i.e. I have to connect once and then just switch database by the command "mysql_select_db()". All databases has seperate tables. Now I am afraid that switching databases 10/11 times in one page may increase the loading time of the page. So I create an extra table on "newsdb" database and trying to link this table with other table. The reason is given in my prev reply.

Share this post


Link to post
Share on other sites
Why connect/disconnect multiple times per page? Connect once, then keep both connections opened for the duration of the script.  There shouldn't be any noticable slowdown.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.