Jump to content

Query in a query?


hansman

Recommended Posts

Here is my code

$query2 = "SELECT * From Songs where band_id = '$id'";
$result2 = mysql_query($query2) or die(mysql_error());
while($row2 = mysql_fetch_array($result2)){
$query = "SELECT * FROM Artists"; 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){

echo $row['bandname']. " - ". $row['yearformed']. " - ". $row['locationformed']. " - ". $row['summary']." ".$row['id']." - ". $row2['name'];;
$id = $row['id'];
print '<td><a href="';
print ($_SERVER['PHP_SELF']);
print '?delete_id='.$id.'">Delete</a></td>';
 print '</tr>'."\n";
}}

?>

 

I have a table named "Songs" and "Artists" I have band_id in "Songs" and i would like every song by each band to come out next to it. What am I doing wrong?

 

--I am connecting to the database fine--

 

Link to comment
https://forums.phpfreaks.com/topic/140629-query-in-a-query/
Share on other sites

Here is my code

$query2 = "SELECT * From Songs where band_id = '$id'";
$result2 = mysql_query($query2) or die(mysql_error());
while($row2 = mysql_fetch_array($result2)){
$query = "SELECT * FROM Artists"; 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){

echo $row['bandname']. " - ". $row['yearformed']. " - ". $row['locationformed']. " - ". $row['summary']." ".$row['id']." - ". $row2['name'];;
$id = $row['id'];
print '<td><a href="';
print ($_SERVER['PHP_SELF']);
print '?delete_id='.$id.'">Delete</a></td>';
 print '</tr>'."\n";
}}

?>

 

I have a table named "Songs" and "Artists" I have band_id in "Songs" and i would like every song by each band to come out next to it. What am I doing wrong?

 

--I am connecting to the database fine--

 

 

You must use this:

 

$query = "SELECT * FROM Artists WHERE something='some values'"; 

Link to comment
https://forums.phpfreaks.com/topic/140629-query-in-a-query/#findComment-735967
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.