Eiolon Posted July 24, 2010 Share Posted July 24, 2010 I am getting this error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, array given in C:\wamp\www\purchase.php on line 52 Line 52 in question: <?php } while ($items = mysql_fetch_assoc($items)); ?> My query: $query_items = "SELECT id, qty, description, price, total FROM items WHERE purchase_id = 8"; $items = mysql_query($query_items) OR die ('Cannot retrieve a list of line items.'); $row_items = mysql_fetch_assoc($items); <table class="data_grid"> <tr> <th width="50">QTY</th> <th>DESCRIPTION</th> <th width="125">PRICE</th> <th width="125">TOTAL</th> <th width="50"></th> </tr> <?php do { ?> <tr> <td width="50"><div align="center"><?php echo $row_items['qty']; ?></div></td> <td><?php echo $row_items['description']; ?></td> <td width="125"><div align="center">$<?php echo $row_items['price']; ?></div></td> <td width="125"><div align="center">$<?php echo $row_items['total']; ?></div></td> <td width="50"><div align="center"><img src="images/delete.png" alt="Delete Line"/> <img src="images/edit.png" alt="Edit Line"/></div></td> </tr> <?php } while ($items = mysql_fetch_assoc($items)); ?> I have 4 entries for the purchase_id. It is displaying the first row twice, and the other 3 arent shown. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 24, 2010 Share Posted July 24, 2010 <?php } while ($items = mysql_fetch_assoc($items)); ?> You are overwritting the result resource the first time your while() condition is evalueate. The second time, $items no longer contains a result resource. Since you are using $row_items in your actual code, I suspect you meant to use $row_items = mysql_fetch_assoc($items). You will find that using a do/while loop requires more lines of code to accomplish the same thing as using a regular while(){} loop and in this case would have likely prevented this error in your code because you would not have needed to type the $row_items = mysql_fetch_assoc($items) twice. Quote Link to comment Share on other sites More sharing options...
Eiolon Posted July 24, 2010 Author Share Posted July 24, 2010 Ha ha! Oh my I didn't even notice that. Thanks very much! 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.