mishasoni Posted July 30, 2009 Share Posted July 30, 2009 Hi there - I am using the below code to display a set of results in two columns. I have used the exact code on another page and it works fine, but on this particular page it produces 2 warnings: Warning: mysql_fetch_assoc(): 5 is not a valid MySQL result resource in /home/agciorg/public_html/events/2009/259/roster.php on line 78 Warning: mysql_fetch_assoc(): 5 is not a valid MySQL result resource in /home/agciorg/public_html/events/2009/259/roster.php on line 106 I've identified the problematic line #s below. Any help as to what could be causing the errors would be much appreciated! Thanks. <?php $number_columns = 2; // manually set the number of columns $break_point = ceil($totalRows_rsWorkshopRegistrants / $number_columns); // divide total rows by 2 to find break points $counter = 0; // start a counter ?> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td></td> <td valign="top"> <?php do { $counter++; // count the output ?> <?php echo $row_rsWorkshopRegistrants['FirstName'] ?> <?php echo $row_rsWorkshopRegistrants['LastName'] ?><br /> <?php if (($counter % $break_point) == 0) { // if current row is equal to break_point echo "</td><td valign='top'>"; // close cell and start a new column } ?> <!-------LINE 106 ----------> <?php } while (($row_rsWorkshopRegistrants = mysql_fetch_assoc($rsWorkshopRegistrants))) ?> </td> </tr> </table> <table border="0"> <?php do { ?> <tr> <td> </td> <td > <?php echo $row_rsWorkshopRegistrants['FirstName'] ?> <?php echo $row_rsWorkshopRegistrants['LastName'] ?> <br /> </td> </tr> <tr> </tr> <!-------LINE 106 ----------> <?php } while ($row_rsWorkshopRegistrants = mysql_fetch_assoc($rsWorkshopRegistrants)); ?> </table> Quote Link to comment Share on other sites More sharing options...
mellis95 Posted July 30, 2009 Share Posted July 30, 2009 What is your query? Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted July 30, 2009 Share Posted July 30, 2009 this means there is something wrong with either your database connect or your query. try putting "or die(mysql_error());" at the end of those lines to see what the problem is Quote Link to comment Share on other sites More sharing options...
mishasoni Posted July 30, 2009 Author Share Posted July 30, 2009 Query is: mysql_select_db($database_AGCI, $AGCI); $query_rsWorkshopRegistrants = "SELECT * FROM Registration_new WHERE Registration_new.EventID = 259"; $rsWorkshopRegistrants = mysql_query($query_rsWorkshopRegistrants, $AGCI) or die(mysql_error()); $row_rsWorkshopRegistrants = mysql_fetch_assoc($rsWorkshopRegistrants); $totalRows_rsWorkshopRegistrants = mysql_num_rows($rsWorkshopRegistrants); It must be connecting to the dB ok because it displays the first record correctly, but nothing after that other than the two warning lines. Quote Link to comment Share on other sites More sharing options...
mishasoni Posted July 30, 2009 Author Share Posted July 30, 2009 Produces the same error if I add "or die(mysql_error());" to the line. Quote Link to comment Share on other sites More sharing options...
JasonO Posted July 30, 2009 Share Posted July 30, 2009 <?php $number_columns = 2; // manually set the number of columns $break_point = ceil($totalRows_rsWorkshopRegistrants / $number_columns); // divide total rows by 2 to find break points $counter = 0; // start a counter ?> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td></td> <td valign="top"> <?php do { $counter++; // count the output ?> <?php echo $row_rsWorkshopRegistrants['FirstName'] ?> <?php echo $row_rsWorkshopRegistrants['LastName'] ?><br /> <?php if (($counter % $break_point) == 0) { // if current row is equal to break_point echo "</td><td valign='top'>"; // close cell and start a new column } ?> <!-------LINE 106 ----------> <?php } while (($row_rsWorkshopRegistrants = mysql_fetch_assoc($rsWorkshopRegistrants, MYSQL_ASSOC))) ?> </td> </tr> </table> <table border="0"> <?php do { ?> <tr> <td> </td> <td > <?php echo $row_rsWorkshopRegistrants['FirstName'] ?> <?php echo $row_rsWorkshopRegistrants['LastName'] ?> <br /> </td> </tr> <tr> </tr> <!-------LINE 106 ----------> <?php } while ($row_rsWorkshopRegistrants = mysql_fetch_assoc($rsWorkshopRegistrants, MYSQL_ASSOC)); ?> </table> Does this make any difference? In a line similar with mine, I have MYSQL_ASSOC after the the variable of the query result. Quote Link to comment Share on other sites More sharing options...
mishasoni Posted July 30, 2009 Author Share Posted July 30, 2009 No. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 30, 2009 Share Posted July 30, 2009 Where is the variable $rsWorkshopRegistrants defined? This is set to the number 5 for some reason. mysql_fetch_array expects a result resource as the first argument, not a number. Quote Link to comment Share on other sites More sharing options...
mishasoni Posted August 4, 2009 Author Share Posted August 4, 2009 The variable $rsWorkshopRegistrants is defined in the header, which is an include file. mysql_select_db($database_AGCI, $AGCI); $query_rsWorkshopRegistrants = "SELECT * FROM users WHERE users.UserEventID = 259"; // **** NEED TO CHANGE EVENTID FOR EACH WORKSHOP **** $rsWorkshopRegistrants = mysql_query($query_rsWorkshopRegistrants, $AGCI) or die(mysql_error()); $row_rsWorkshopRegistrants = mysql_fetch_assoc($rsWorkshopRegistrants); $totalRows_rsWorkshopRegistrants = mysql_num_rows($rsWorkshopRegistrants); 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.