-1
<? while($blog2 = mysql_fetch_array($blog))
{  
    $tag = ("select * from blogtag_ref inner join blogtag on blogtag_ref.tag_id = blogtag.tag_id where blogtag_ref.blog_id = '".$blog2['blog_id']."' ") or die(mysql_error());  
?>
<table width="1040" border="0" cellspacing="0" cellpadding="10" align="center">
  <tr>
    <td><div class="blogtitle"><? echo $blog2['subject']; ?></div></td>
  </tr>
    <tr>
    <td><div class="blogdate"><? echo $date; ?></div> // 


    <? while($tag2 = mysql_fetch_array($tag))
    { ?>
  <div class="blogtag"><? echo $tag2['tag']; ?></div> /     

    <? }  ?>

It gives me Warning: mysql_fetch_assoc() expects parameter 1 to be resource

I know my SQL is correct, if I echo the $tag ... and I copy paste in phpmyadmin ... it gives me the results...

is it because I can't put a while inside a while ?

Robbie Wxyz
  • 7,326
  • 2
  • 29
  • 45
user3011784
  • 807
  • 1
  • 8
  • 26

3 Answers3

2

The variable you are referring to ($tag) is not a result, mysql_fetch_array() needs a result from mysql_query

$tag = mysql_query("select ....") or die('yeah');
while($tag2 = mysql_fetch_array($tag))
Tutelage Systems
  • 1,574
  • 1
  • 8
  • 6
0

You need to evaluate your SQL statement before you can fetch data from it. Plug your query info 'mysql_query'.

$tag = ("select * from blogtag_ref ....
$result = mysql_query($tag, $db_connection);

Then, you can use $result:

while($tag2 = mysql_fetch_array($result)) {
Quixrick
  • 3,160
  • 1
  • 12
  • 15
0
$tag = ("select * ...

should read

$tag = mysql_query("select * ...
SparK
  • 5,073
  • 2
  • 23
  • 32