Jump to content

[SOLVED] Problem with the "mysql_fetch_assoc" function in while loop


tmyonline

Recommended Posts

Hi guys:

 

I have this piece of code that I wrote:

 

...

 

$i = 0;

while ($imgArray  = mysql_fetch_assoc($imgResult)) {    // line 184

  if ($i % 12 == 0) {

    echo '<tr>';

  } 

  echo '<td id="num-size">';    

    $locArray[$i] = $imgArray['LOC_key'];

    echo '<img src="' . $imgArray['thumbnail'] .'" alt="image' . $i . '" width="50" height="50" />';

    echo $i + 1;

  echo '</td>';

  if ($i % 12 == 11) {

    echo '</tr>';

  }

  $i++;

}

...

 

This piece of code works fine on my machine.  However, when uploading it to the server, I got the following warning:

 

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/.euclid/aamnva_db/db/LE/entry_matrix.php on line 184  (line 184 is the beginning of the while loop above)

 

 

Consequently, the set of image gallery failed to display (it did display locally on my computer).  Any ideas?  Many thanks.

Link to comment
Share on other sites

Here is some more code down below.  I've tested my SQL statement in phpMyAdmin and it worked fine.  I've also done several "echo" inside and outside the while loop.  Locally on my machine, it did enter the while loop.  However, on the server, it did not enter the while loop.

 

 

$k = 1193;

$_SESSION['K'] = $k;

 

$imgSQL    = "SELECT experiences_loc_item_jn.LOC_key, loc_item.thumbnail FROM experiences_loc_item_jn, loc_item WHERE experiences_loc_item_jn.experiences = $k AND experiences_loc_item_jn.LOC_key = loc_item.LOC_key";

$imgResult = mysql_db_query($db,$imgSQL,$cid);

 

$i = 0;

while ($imgArray  = mysql_fetch_assoc($imgResult)) {    // line 184

  echo "I got here";

  if ($i % 12 == 0) {

    echo '<tr>';

  } 

    echo '<td id="num-size">';     

        $locArray[$i] = $imgArray['LOC_key'];

        echo '<img src="' . $imgArray['thumbnail'] .'" alt="image' . $i . '" width="50" height="50" />';

        echo $i + 1;

    echo '</td>';

  if ($i % 12 == 11) {

    echo '</tr>';

  }

  $i++;

}

...

 

Link to comment
Share on other sites

Thank you so much Ken and thank you all who have helped me.

 

Ken, your suggestion is of enormous help.  I did exactly what you suggested and MySQL pinpointed the error that one table being used does not exist in the database.  My client told me that the database they gave me and the one currently on the server are identical but they are really not.  That explains why it works on my local machine and not on the server.  I have spent hours trying to resolve this problem and hopeless.  Now, I see that the

 

"or die("Problem with the query: $imgSQL<br>" . mysql_error()"

 

is really helpful because it displays not ony the error but also what goes wrong.  Many thanks again!

 

Tommy

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.