Jump to content

Build an array with SQL


soltek

Recommended Posts

Hello again, guys!

 

I'm trying to do this:

 

Get $user_ID -> SELECT FROM favorites WHERE user="$user_ID" -> Now I should create an array with the ID of all the results of the previous command ->

SELECT FROM books WHERE genre="$favorites_ID" -> populate a html table.

 

The part I've no idea about how to do is building an array with the results and then using the SELECT command, find in the other tables the match.

 

Could you please give me a hand - one more time?

Link to comment
https://forums.phpfreaks.com/topic/254134-build-an-array-with-sql/
Share on other sites

I think a query like this will give you what your looking for:

 

echo "<table>";
$sql = mysql_query("select * from favorites f left join books b on(f.favorites_id = b.genre) where f.user = $user_ID");
while($row = mysql_fetch_assoc($sql)){
echo <<<ROWS
<tr>
	<td>{$row["book_title"]}</td>
	<td>{$row["book_genre"]}</td>
</tr>
ROWS;
}
echo "</table>";

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.