Jump to content

[SOLVED] include in while loop?


Zeradin

Recommended Posts

Does include work differently in while loops? The overall thing here is actually really complex, but hopefully the problem simple. This:

	<table width="100%" height="100%" border=1>';
		 while($listinfo = mysql_fetch_assoc($result)) {
			$userid = $listinfo['id'];
			echo '<tr><td>';
			echo $userid;
			//include('../pblock.php');
			echo '</td></tr>';
		 }
		 echo '</table>';

gives me a list of user ids in the table just right

however,

<table width="100%" height="100%" border=1>';
		 while($listinfo = mysql_fetch_assoc($result)) {
			$userid = $listinfo['id'];
			echo '<tr><td>';
			//echo $userid;
			include('../pblock.php');
			echo '</td></tr>';
		 }
		 echo '</table>';

 

gives me the first include only and doesn't go through all the other values. Why? Thanks.=)

Link to comment
https://forums.phpfreaks.com/topic/125509-solved-include-in-while-loop/
Share on other sites

Something in pblock.php is either overwriting variables in your main code or there is a function definition in it that is causing a fatal runtime error when it gets redefined in the loop.

 

The only way to get specific help with what your code is doing, is to post your code.

<?php

if ($userid != NULL) {

// create query
$query = 'SELECT * FROM users WHERE id = "'.$userid.'"';
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$info = mysql_fetch_array($result) or die ("Error in query: $query. ".mysql_error());

$lastquery = 'SELECT "review" AS type, id, title, `timestamp` FROM reviews AS r WHERE r.reviewer = "'.$info['username'].'"
AND visible = 1
UNION ALL
SELECT "article", id, title, `timestamp` FROM articles AS a WHERE a.writer = "'.$info['username'].'" 
AND visible = 1 ORDER BY `timestamp` DESC';
$lastresult = mysql_query($lastquery) or die ("Error in query: $lastquery. ".mysql_error());


echo '<table width="100%%" border="1" cellspacing="3" cellpadding="3">
      <tr>
        <td width="11%" valign="top" bgcolor="#000000" align="center" class="white">
		<a href="../contact/index.php?ctyp=profiles&userid='.$info['id'].'"><strong>'.$info['username'].'</strong>
		<br />
      		<img src="../members/mimages/'.$info['image'].'" alt="Profile Image" width="60" height="60" border="0" align="center" /></a>
  	</td>

        <td width="89%" valign="top" bgcolor="#000000">

		<table width="100%" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td width="30%" valign="top" class="white">
					<strong><span class="poster">'.$info['title'].'</span></strong>
				</td>

			  <td width="70%" valign="top"><span class="white">
					 <div align="right"><font size="1">Rating: Not Yet Available</font> <img src="../images/bar-fill2.jpg" /></div>
			  </td>
			</tr>
		</table>
		<hr />';

if ($comm == NULL) {
      echo '
  <span class="white">
  <strong>About:</strong> <br />';
  echo nl2br($info['pblurb']);
  echo '<br /></span>
     

      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr> 
          <td width="30%" valign="bottom" class="white"> 

	  			<strong>Most Recent Submission: </strong>';

if (mysql_num_rows($lastresult) > 0) {
$lastinfo = mysql_fetch_assoc($lastresult) or die ("Error in query: $lastquery. ".mysql_error());
$type = $lastinfo['type'];
if ($type=='show' || $type=='venue' || $type=='album'){
		$type2='music';
		}	
	else {
		$type2=$type;
		}
echo '<a href="index.php?rtyp='.$type2.'&id='.$lastinfo['id'].'">'.$lastinfo['title'].'</a> <span class="poster">('.$lastinfo['type'].')</span>';
}
else {
echo "No reviews submitted";
}
echo '</td>
	</tr>
      </table>';
      }
  else {
   echo nl2br('<span class="white"> <strong>'.$comm.'</strong>');
  }
   echo '</td>
      </tr>
  </table>';
  }
else {
echo 'error';
}
?>

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.