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
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>";

Link to comment
Share on other sites

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.