1.

Solve : Linking databse tables using PHPmyadmin and PHP?

Answer»

Hi,

I have created 2 tables in PHPmyAdmin, 1 table needs to be linked to the other as follows:-

Table 1 = Field1name = Team = Arsenal, Aston Villa, Blackburn etc....
Table 1 = Field2name = Points = 3, 6, 3 etc

Table 2 = Field2name = Position = 1, 2, 3 ===> 20

as the points are accrued the data is sorted and the sequence of the teams move to there respective position in the list.

I have a PHP program which calls the MySQL database.

I would appreciate any guidance given

Many thanksI'm not totally sure, but I don't think mysql actually links the tables together. I believe you are supposed to tell php which tables you want it to use together. I can't REALLY tell what your table structure looks LIKE with the given depiction. Could you copy the output from mysql after a "describe Table1;" command?
More info would be helpful.Hi,

this is the output of my table so far:


Pos    TEAM             P W D L F A GD Pts
  1        Arsenal        0  0  0 0 0 0 0    0
  2        Aston Villa    0 0 0 0 0 0 0     0
  3        Birmingham  0 0 0 0 0 0 0     3
  4        Blackburn     0 0 0 0 0 0 0     0

as you can see if the points column is sorted, then the sequence of the table will look like this :-

Pos    TEAM             P W D L F A GD Pts
  1        Birmingham  0  0  0 0 0 0 0    3
  2        Arsenal        0 0 0 0 0 0 0      0
  3        Aston Villa    0 0 0 0 0 0 0      0
  4        Blackburn     0 0 0 0 0 0 0      0

my problem is I do not know how to sort and sequence the table. 

Many thanksIn my mind, probably the easiest thing to do is to put the points into its own table and have it reference the team table by number. Then you could sort the points and then insert the appropriate team where the reference is. I think all of that would need to happen on the php side.

Here's what the table structure might look like:
TEAMTable
Pos    TEAM             P W D L F A GD  PointsRef
  1        Arsenal        0  0  0 0 0 0 0    1
  2        Aston Villa    0 0 0 0 0 0 0     2
  3        Birmingham  0 0 0 0 0 0 0     3
  4        Blackburn     0 0 0 0 0 0 0     4

PointTable
TeamRef  Points
1              0
2              0
3              3
4              0

Now, when you go to sort by points, call the PointTable first and sort it. Then replace the TeamRef numbers with their corresponding team from TeamTable.
After sorting it, it would look like this:
PointTable
TeamRef  Points
3              3
1              0
2              0
4              0
and then once you replace the numbers with team names:
PointTable
TeamRef       Points
Birmingham   3
Arsenal          0
Aston Villa     0
Blackburn      0

Is there a easier way? Maybe. Would this way take a lot of coding and some database normalization skills? Probably. Would I ask the people at www.phpbuilder.net/board for more advice? Absolutely.
Good Luck, and if you have any more questions, I'll do my best to answer in an intelligent way. THANKS for the great response,

what you have suggested makes perfect sense.  I will report back with results.

Kind Regards



Discussion

No Comment Found