Jump to content


Photo

How to make Table relation?


  • Please log in to reply
5 replies to this topic

#1 abdfahim

abdfahim
  • Members
  • PipPipPip
  • Abd Fahim
  • 535 posts

Posted 21 August 2006 - 05:36 AM

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.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 August 2006 - 05:35 PM

The only way to actually do this is using triggers (MySQL 5), but I'm not sure why you want to do this.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 abdfahim

abdfahim
  • Members
  • PipPipPip
  • Abd Fahim
  • 535 posts

Posted 22 August 2006 - 08:32 AM

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.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 August 2006 - 01:43 PM

This different database is where?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 abdfahim

abdfahim
  • Members
  • PipPipPip
  • Abd Fahim
  • 535 posts

Posted 23 August 2006 - 07:52 AM

Ok, the whole situation is -
I have 4 database "userdb","forumdb","newsdb","profiledb". All databases are in the same server, 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.

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 23 August 2006 - 01:16 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users