Page 1 of 1

Repeat Region cuts away my first displayed record!

Posted: Thu Aug 01, 2002 1:17 pm
by sabka
Need a little help with this one. I'm pulling records out of a mysql database using php.
What I'm trying to do is a repeat region for the record-display; and if no records exists, display an error message.

For some reason, this code cuts away the first record in the database:.
example: database had the following records:

Record1
Record2
Record2
Record3...

The code displays

Record2
Record3...



Here is the code before the <head> part:

Code: Select all

<?php require_once('Connections/connection.php'); ?> 
<?php
$colname_Recordset1 = "1";
if (isset($HTTP_GET_VARS&#1111;'week'])) &#123;
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS&#1111;'week'] : addslashes($HTTP_GET_VARS&#1111;'week']);
&#125;
$colname2_Recordset1 = "2002";
if (isset($HTTP_GET_VARS&#1111;'year'])) &#123;
  $colname2_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS&#1111;'year'] : addslashes($HTTP_GET_VARS&#1111;'year']);
&#125;
mysql_select_db($database_connection, $connection);
$query_Recordset1 = sprintf("SELECT * FROM playlist WHERE week = %s AND year = %s ORDER BY `order` ASC", $colname_Recordset1,$colname2_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $connection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
And here is the part inside the body of my page:

Code: Select all

<?php 
  if ($row_Recordset1 = mysql_fetch_assoc($Recordset1))&#123;
  do &#123; ?>
  <tr> 
    <td bgcolor="#CCCCCC"><div align="center"><?php echo $row_Recordset1&#1111;'artists']; ?></div></td>
    <td bgcolor="#CCCCCC"><div align="center"><?php echo $row_Recordset1&#1111;'track']; ?></div></td>
    <td bgcolor="#CCCCCC"><div align="center"><?php echo $row_Recordset1&#1111;'order']; ?></div></td>
  </tr>
  <?php &#125; while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));&#125;
      else &#123; ?>
  <tr> 
    <td colspan="3" bgcolor="#CCCCCC" align="center"><?php echo "Sorry, but there is no Playlist for this week!" ?>  </td>

  </tr>
  <?php &#125;
    

     ?>
Many thanks

Posted: Fri Aug 02, 2002 2:06 am
by twigletmac
It's because you are pulling the first row from the database before your mysql_num_rows() line so when you go into the while loop you start on the second row of the result set. Try:

Code: Select all

<?php require_once('Connections/connection.php'); ?> 
<?php 
$colname_Recordset1 = 1; 
if (isset($HTTP_GET_VARS&#1111;'week'])) &#123; 
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS&#1111;'week'] : addslashes($HTTP_GET_VARS&#1111;'week']); 
&#125; 
$colname2_Recordset1 = 2002; 
if (isset($HTTP_GET_VARS&#1111;'year'])) &#123; 
  $colname2_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS&#1111;'year'] : addslashes($HTTP_GET_VARS&#1111;'year']); 
&#125; 
mysql_select_db($database_connection, $connection); 
$query_Recordset1 = "SELECT * FROM playlist WHERE week = '$colname_Recordset1' AND year = '$colname_Recordset2' ORDER BY `order` ASC"; 

$Recordset1 = mysql_query($query_Recordset1, $connection) or die(mysql_error()); 

?>
and

Code: Select all

<?php
if (!empty(mysql_num_rows($Recordset1))) &#123;
	while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) &#123; 
?> 
  <tr> 
    <td bgcolor="#CCCCCC" align="center"><?php echo $row_Recordset1&#1111;'artists']; ?></td> 
    <td bgcolor="#CCCCCC" align="center"><?php echo $row_Recordset1&#1111;'track']; ?></td> 
    <td bgcolor="#CCCCCC" align="center"><?php echo $row_Recordset1&#1111;'order']; ?></td> 
  </tr> 
<?php 
	&#125; 
&#125; else &#123;
?>
  <tr> 
    <td colspan="3" bgcolor="#CCCCCC" align="center">Sorry, but there is no Playlist for this week!</td> 
  </tr> 
<?php 
&#125; 
?>
Mac

Posted: Fri Aug 02, 2002 11:18 am
by sabka
Wow - who knew!
Thank you very much!