Jump to content

[SOLVED] While loop only returning one block of information . . . several are present


Styles2304

Recommended Posts

This is a "myspace" styled message bored for my Church's Youth Group. The problem is that there are multiple entries in the database where the $ProfilePost = 1 which is the value of $_GET['IndexNo']; but only one of the entries shows up. This is a lot of code, I know but does anyone see anything wrong? Just a note, I know the date functions I used aren't very efficient . . . I just haven't taken time to go back and correct it yet.

 

      <!-- Friend's Comments -->
      <div id="blog_yellow">
        <?php if ($_SESSION['user_index'] == $_GET['IndexNo']) {
        echo '<a id="leavecomment" href="profile.php?mode=comment&IndexNo=' . $_GET['IndexNo'] . '" title="Leave Comment"><span class="hide">Leave Comment</span></a>';
        } ?>
        <div id="blog_header">
          <font class="blogh1">
            Friend's Comments
          </font>
        </div>
      </div>
      
      <P></P>
      
      <div id="blog_container">
      <?php
        $query = "SELECT * FROM FriendComments WHERE ProfilePost = '" . $_GET['IndexNo'] . "';";

        $result = mysql_query($query, $link)
          or die(mysql_error());
          
        $post = ' ';

        while ($row = mysql_fetch_array($result)) {
          $IndexNo = $row['IndexNo'];
          $ProfilePost = $row['ProfilePost'];
          $PostBy = $row['PostBy'];
          $Date = $row['Date'];
          $Time = $row['Time'];
          $AoP = $row['AoP'];
          $Post = $row['Post'];
          
          $query = "SELECT IndexNo, FirstName, LastName, Picture, OnlineStatus FROM Profile WHERE IndexNo = '" . $PostBy . "';";

          $result = mysql_query($query, $link)
            or die(mysql_error());

          while ($row = mysql_fetch_array($result)) {
            $CommentIndex = $row['IndexNo'];
            $CommentFirstName = $row['FirstName'];
            $CommentLastName = $row['LastName'];
            $CommentPicture = $row['Picture'];
            $commentStatus = $row['OnlineStatus'];
            $PostBy = $CommentFirstName;
            $PostBy .= ' ';
            $PostBy .= substr($CommentLastName, 0, 1);
          }
          
          $DateInfo = explode("-", $Date);
          
          $Year = $DateInfo[0];
          $Month = $DateInfo[1];
          $Day = $DateInfo[2];
          
          $TimeTest = substr($Time, 0, 1);
  
          if ($TimeTest == '0') {
            $TimeData = substr($Time, 1, 4);
            $Time = $TimeData;
          }
          
          $post .=<<<EOD
          
          <table width="90%" cellpadding="0" cellspacing="0" border="0" class="blog">
            <tr>
              <td height="10" valign="top" align="center">
                <font class="blogh2">
                  <b>$PostBy</b>
                </font>
              </td>
              
              <td height="10" valign="top" align="left" colspan="2">
                <font class="blogh2">
                  <b>$Month/$Day/$Year @ $Time $AoP</b>
                </font>
              </td>
            </tr>
            
            <tr>
              <td width="90" valign="top" align="center">
                <a href="profile.php?IndexNo=$CommentIndex"><img src="images/$CommentPicture" width="64" height="81" border="0"></a>
                <P></P>
EOD;
                if ($CTime - $OnlineStatus >300) {
                  $post .=<<<EOD
                  <a href="profile.php?IndexNo=$CommentIndex"><img src="images/offline.png" border="0"></a>
EOD;
                } else {
                  $post .=<<<EOD
                  <a href="profile.php?IndexNo=$CommentIndex"><img src="images/online.png" border="0"></a>
EOD;
                }

          $post .=<<<EOD
              </td>
              
              <td valign="top" colspan="2">
                <font class="blogh2">
                  $Post
                </font>
              </td>
            </tr>
          </table>
          
          <table width="90%" cellpadding="0" cellspacing="0" border="0" class="blog">
            <tr>
              <td valign="middle" align="center" width="50%" height="20">
                <a id="comment" href="#" title="Comment Back"><span class="hide">Comment Back</span></a> 
              </td>
              
              <td valign="middle" align="center" width="50%" height="20">
                <a id="viewprofile" href="profile.php?IndexNo=$CommentIndex" title="View Profile"><span class="hide">View Profile</span></a> 
              </td>
            </tr>
          </table>
EOD;
}

//MODE: COMMENT
if ($_GET['mode'] == 'comment') {
  echo '<form method="post" action="profile.php?mode=commentpost&IndexNo=' . $_GET['IndexNo'] . '">';
  echo '<textarea rows="5" cols="30" name="Comment" wrap="soft"></textarea> <br>';
  echo '<input type="image" src="images/submit.gif" border="0" name="submit"> <a href="profile.php?IndexNo=' . $_GET['IndexNo'] . '"><img src="images/cancel.gif" border="0"></a>';
  echo '</form><p>';
}

echo $post;
      ?>
      </div>
      <!-- Friend's Comments -->

You're resetting $result AND $row, rename your variables, this should work:

 

      <!-- Friend's Comments -->
      <div id="blog_yellow">
        <?php if ($_SESSION['user_index'] == $_GET['IndexNo']) {
        echo '<a id="leavecomment" href="profile.php?mode=comment&IndexNo=' . $_GET['IndexNo'] . '" title="Leave Comment"><span class="hide">Leave Comment</span></a>';
        } ?>
        <div id="blog_header">
          <font class="blogh1">
            Friend's Comments
          </font>
        </div>
      </div>
      
      <P></P>
      
      <div id="blog_container">
      <?php
        $PostQuery = "SELECT * FROM FriendComments WHERE ProfilePost = '" . $_GET['IndexNo'] . "';";

        $PostResult = mysql_query($PostQuery, $link)
          or die(mysql_error());
          
        $post = ' ';

        while ($PostRow = mysql_fetch_array($PostResult)) {
          $IndexNo = $PostRow['IndexNo'];
          $ProfilePost = $PostRow['ProfilePost'];
          $PostBy = $PostRow['PostBy'];
          $Date = $PostRow['Date'];
          $Time = $PostRow['Time'];
          $AoP = $PostRow['AoP'];
          $Post = $PostRow['Post'];
          
          $ProfileQuery = "SELECT IndexNo, FirstName, LastName, Picture, OnlineStatus FROM Profile WHERE IndexNo = '" . $PostBy . "';";

          $ProfileResult = mysql_query($ProfileQuery, $link)
            or die(mysql_error());

          while ($ProfileRow= mysql_fetch_array($ProfileResult)) {
            $CommentIndex = $ProfileRow['IndexNo'];
            $CommentFirstName = $ProfileRow['FirstName'];
            $CommentLastName = $ProfileRow['LastName'];
            $CommentPicture = $ProfileRow['Picture'];
            $commentStatus = $ProfileRow['OnlineStatus'];
            $PostBy = $CommentFirstName;
            $PostBy .= ' ';
            $PostBy .= substr($CommentLastName, 0, 1);
          }
          
          $DateInfo = explode("-", $Date);
          
          $Year = $DateInfo[0];
          $Month = $DateInfo[1];
          $Day = $DateInfo[2];
          
          $TimeTest = substr($Time, 0, 1);
  
          if ($TimeTest == '0') {
            $TimeData = substr($Time, 1, 4);
            $Time = $TimeData;
          }
          
          $post .=<<<EOD
          
          <table width="90%" cellpadding="0" cellspacing="0" border="0" class="blog">
            <tr>
              <td height="10" valign="top" align="center">
                <font class="blogh2">
                  <b>$PostBy</b>
                </font>
              </td>
              
              <td height="10" valign="top" align="left" colspan="2">
                <font class="blogh2">
                  <b>$Month/$Day/$Year @ $Time $AoP</b>
                </font>
              </td>
            </tr>
            
            <tr>
              <td width="90" valign="top" align="center">
                <a href="profile.php?IndexNo=$CommentIndex"><img src="images/$CommentPicture" width="64" height="81" border="0"></a>
                <P></P>
EOD;
                if ($CTime - $OnlineStatus >300) {
                  $post .=<<<EOD
                  <a href="profile.php?IndexNo=$CommentIndex"><img src="images/offline.png" border="0"></a>
EOD;
                } else {
                  $post .=<<<EOD
                  <a href="profile.php?IndexNo=$CommentIndex"><img src="images/online.png" border="0"></a>
EOD;
                }

          $post .=<<<EOD
              </td>
              
              <td valign="top" colspan="2">
                <font class="blogh2">
                  $Post
                </font>
              </td>
            </tr>
          </table>
          
          <table width="90%" cellpadding="0" cellspacing="0" border="0" class="blog">
            <tr>
              <td valign="middle" align="center" width="50%" height="20">
                <a id="comment" href="#" title="Comment Back"><span class="hide">Comment Back</span></a> 
              </td>
              
              <td valign="middle" align="center" width="50%" height="20">
                <a id="viewprofile" href="profile.php?IndexNo=$CommentIndex" title="View Profile"><span class="hide">View Profile</span></a> 
              </td>
            </tr>
          </table>
EOD;
}

//MODE: COMMENT
if ($_GET['mode'] == 'comment') {
  echo '<form method="post" action="profile.php?mode=commentpost&IndexNo=' . $_GET['IndexNo'] . '">';
  echo '<textarea rows="5" cols="30" name="Comment" wrap="soft"></textarea> <br>';
  echo '<input type="image" src="images/submit.gif" border="0" name="submit"> <a href="profile.php?IndexNo=' . $_GET['IndexNo'] . '"><img src="images/cancel.gif" border="0"></a>';
  echo '</form><p>';
}

echo $post;
      ?>
      </div>
      <!-- Friend's Comments -->

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.