tmyonline Posted November 21, 2007 Share Posted November 21, 2007 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. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 21, 2007 Share Posted November 21, 2007 You need to do error checking BEFORE the while loop, where the query was sent. You didn't provide that part of the code. Like $imgResult = mysql_query($sql) or whatever. PhREEEk Quote Link to comment Share on other sites More sharing options...
tmyonline Posted November 21, 2007 Author Share Posted November 21, 2007 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++; } ... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 21, 2007 Share Posted November 21, 2007 Change this line <?php $imgResult = mysql_db_query($db,$imgSQL,$cid); ?> to <?php $imgResult = mysql_query($imgSQL) or die("Problem with the query: $imgSQL<br>" . mysql_error()); ?> And see if any errors are displayed. Ken Quote Link to comment Share on other sites More sharing options...
tmyonline Posted November 21, 2007 Author Share Posted November 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.