Jump to content

Recommended Posts

Is there a way to check two tables and sort of nest the SQL?

 

This is what I want to do in theory:

$result = mysql_query("SELECT * FROM MusicFiles ORDER BY SongTitle ASC");
        while($row = @mysql_fetch_array($result)){

	$FileID = $row['MusicFiles_ID'];
	echo <all results>;
	$result2 = mysql_query("SELECT * FROM Chords_Charts_Lyrics WHERE MusicFiles_ID ='$FileID'");
        	
	while($row2 = @mysql_fetch_array($result2)){
		echo <all sub related results>;
	}

}

 

The tables are:

Table: MusicFiles

MusicFiles_ID

Type

SongTitle

SingerGroup

AlbumName

 

 

Table: Chords_Loops_Lyrics

CLL_ID

MusicFiles_ID

Type

FileName

 

The idea is that one song may have many other files attached to is... so I want the output to basically be like this:

 

1  | Song  |  Dead Or Alive  | Bon Jovi  |  Best Of Bon Jovi

2  | Song  |  Outlaws        | Bon Jovi  |  Best Of Bon Jovi

              -> Lyrics

              -> Chords

3  | Song  |  Stairway to... | Eagles    |  Classics

Link to comment
https://forums.phpfreaks.com/topic/233688-two-tables-connecting-the-data/
Share on other sites

Erm...uh... nvm... solved my own problem.

 

This works beautifully... not sure if it's the best method or not, but it works.

$result = mysql_query("SELECT * FROM MusicFiles ORDER BY SongTitle ASC");
        while($row = @mysql_fetch_array($result)){

	$FileID = $row['MusicFiles_ID'];

	echo $row['SongTitle']."<br>";

		$result2 = mysql_query("SELECT * FROM Chords_Loops_Lyrics WHERE MusicFiles_ID='$FileID'");
        	while($row2 = @mysql_fetch_array($result2)){
			echo "->".$row2['Type']."<br>";
		}
	}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.