Jump to content

Trouble displaying results in 2 columns


mishasoni

Recommended Posts

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>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/168067-trouble-displaying-results-in-2-columns/
Share on other sites

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.

<?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.

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.