Warning: mysql_fetch_assoc(): 4

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ATH0
Forum Newbie
Posts: 19
Joined: Mon Oct 03, 2005 12:39 pm

Warning: mysql_fetch_assoc(): 4

Post by ATH0 »

Hi to all !.

This is my first posting to this forum ( drums :-)).

I have db (mySql ) with 3 records.
When i run query to make list of all those records ( where id = 10 ) i get one record corectly displayed but instead second record i get error message:

Warning: mysql_fetch_assoc(): 4

Why?


p.s. Everything else is working fine ( connections, selects and so on )..


ATH0
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Please post your code. Are you connecting to the database?
ATH0
Forum Newbie
Posts: 19
Joined: Mon Oct 03, 2005 12:39 pm

Post by ATH0 »

Code: Select all

<?php
mysql_select_db($database_dbConn, $dbConn);
$query_dbNew 	= "SELECT images.image, images.desc FROM images WHERE images.group='100'";
$dbNew 		= mysql_query($query_dbNew, $dbConn) or die(mysql_error());
$row_dbNew 	= mysql_fetch_assoc($dbNew);
$totalRows_dbNew 	= mysql_num_rows($dbNew);

mysql_free_result($dbNew);
?>
<!------------------------------------------------->

<div align="center">
  <table border="1" cellpadding="1" cellspacing="1">
    <?php do { ?>
    <tr>
      <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
      <?php echo $row_dbNew['image']; ?></font></td>
      
      <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
      <?php echo $row_dbNew['desc']; ?></font></td>
      <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
    </tr>
    
   <?php } while 
		 ($row_dbNew = mysql_fetch_assoc($dbNew)); 
		 
   ?>
  
</table>
----------------
I am connected to db and i can work with db....

2.) Table creation:
Maybe dump question... Since i have 3 records (2 of them should mach the query ), is it possible that there is a problem with "dinamic table creation" , becuse i allways get one record displayed(regardless how many records are in DB)...
ruchit
Forum Commoner
Posts: 53
Joined: Mon Sep 26, 2005 6:03 am

Post by ruchit »

the problem is here

Code: Select all

mysql_free_result($dbNew);
you are free-ing up the recordset aftering fetching the first row of the data... then you are trying to fetch the remaining rows in the do-while loop.
IMHO, you shold improve your coding style... try to study few codes posted on the forum or take some reference from a book.
ATH0
Forum Newbie
Posts: 19
Joined: Mon Oct 03, 2005 12:39 pm

[SOLVED]

Post by ATH0 »

:--)).
Well, it looks like i have to stop drinking. ;--)
Thank you for your replay and solved question !

ATH0
Post Reply