Current location: Hot Scripts Forums » Programming Languages » PHP » Linking two tables within a db


Linking two tables within a db

Reply
  #1 (permalink)  
Old 10-12-03, 05:46 AM
Ported Valhalla Ported Valhalla is offline
New Member
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Linking two tables within a db

Just wondering if anyone had any pointers for a problem I've got.

I've got 2 tables within my db (results and fixtures)

The results table is added to each time a game takes place.

Is there way of linking the 2 tables so that when a result is added, the script sees the id or similar field and displays the next fixture.

Ie: If the id of the last result is 3 then is there a way to display id 4 from the fixtures table.

So, in sum, whatever id the latest entry in the results table is, the id of the entry requested from the fixtures table needs to be 1 higher.

Hopefully, I've made myself understandable without being to vague.
Reply With Quote
  #2 (permalink)  
Old 10-14-03, 04:53 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
yeah that's possible and even easy
all you need is something like that :
PHP Code:

$check=mysql_query("SELECT id FROM results WHERE id='$the_last_id_sent'")or die(mysql_error());

$id=mysql_fetch_row($check);

settype($id[0], "integer");//convert the id into integer
$new=$id[0]+1

/*now we fetch the next fixture */
$bring=mysql_query("SELECT nextfixture FROM fixture WHERE id='$new'")or Die(mysql_error());

$fixture=mysql_fetch_row($bring);

echo 
$fixture[0]; 
I assumed that you know the last ID of the result ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 10-14-03, 10:36 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
just incase you are not aware of the last id of the resutl .. you could just use the max() in the first SELECT statment .. like this :
PHP Code:

check=mysql_query("SELECT max(id) as last_id FROM results")or die(mysql_error()); 

and the rest is the same ..
this time I assumed you are using auto increment in your ID number .. so it would take the highest id number ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking in table perleo PHP 2 10-09-03 12:41 PM
Change the tables in a postnuke theme Marko PHP 0 08-18-03 02:41 PM
sorting multiple tables elmeto PHP 1 08-13-03 09:07 AM
script that measures height of tables and vertically aligns nested tables amj01 Script Requests 1 07-04-03 01:20 PM
Dynamic color tables frik PHP 6 06-15-03 11:58 AM


All times are GMT -5. The time now is 07:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.