GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Nov-2003, 15:30
soviet soviet is offline
New Member
 
Join Date: Nov 2003
Posts: 1
soviet is an unknown quantity at this point

Selecting from 2 tables at the same time


I am new to using MySQL and I am trying to switch my site over to make it more dynamic. After reading up on databases and Normalizing them I have set it up so that there are 2 tables:
one called "album"
the other "artists"

I have an id in the Albums table called artID which is a reference [foreign key?] to the Artists table.

How should I set my select statement up so that I can get the info from a particular row from the Albums table which also has a link to the Artists table as well?

Here's the current SELECT statement:
$query="SELECT * FROM album WHERE albID = $albID";
$result=mysql_query($query) or die(mysql_error());

I then pass the albID through a query string in the URL, I am hoping to pass the artID in their as well, but that's where I get lost as to how to pull that info out of the other table....

any info is much appreciated....

thanks
  #2  
Old 07-Nov-2003, 16:15
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road
You could try something like:

PHP Code:

$result=mysql_query("SELECT * FROM album, art WHERE album.albid=art.artid ORDER BY artid"); 




Hope that helps point you in the right direction. If not wait for JdS
  #3  
Old 07-Nov-2003, 23:15
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Hello soviet,

If you have read and understood 'normalizing' a database, you should have used at least 3 tables in this situation. ONE artist to MANY albums.

Code:
TABLE: ARTISTS artist_id | artist -----------+-------- 1 | Garth 2 | Jay 3 | Rob TABLE: ALBUMS album_id | album ----------+--------- 1 | National Anthems of the World 2 | Nursery Rhymes for Geeks 3 | Coding Blues 4 | Yet Another Bulletin Song 5 | The Dog Ate My Script! TABLE: ART2ALB artist_id | album_id ------------+--------- 1 | 3 1 | 4 1 | 5 2 | 1 3 | 2
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Display Size and maybe download time BobbyDouglas MySQL / PHP Forum 5 08-Nov-2003 00:18
finding time efficiency of STL goathens CPP / C++ Forum 1 28-Sep-2003 17:41
Need a script for selecting random tabels and from those tabels selecting random ques mlt MySQL / PHP Forum 2 12-Sep-2003 09:01
ambiguity in time field zuzupus MySQL / PHP Forum 9 28-Jul-2003 08:40
time Problem zuzupus MySQL / PHP Forum 9 24-Jul-2003 07:02

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:40.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.