Zeradin Posted September 23, 2008 Share Posted September 23, 2008 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.=) Quote Link to comment https://forums.phpfreaks.com/topic/125509-solved-include-in-while-loop/ Share on other sites More sharing options...
wildteen88 Posted September 23, 2008 Share Posted September 23, 2008 Whats happening in pblock.php? Quote Link to comment https://forums.phpfreaks.com/topic/125509-solved-include-in-while-loop/#findComment-648884 Share on other sites More sharing options...
Zeradin Posted September 23, 2008 Author Share Posted September 23, 2008 if userid exists it selects all the data from the users table and populates a table in a table and also some information about reviews etc it's 84 lines of code so i don't want to post it, but that's the basics. Quote Link to comment https://forums.phpfreaks.com/topic/125509-solved-include-in-while-loop/#findComment-648888 Share on other sites More sharing options...
PFMaBiSmAd Posted September 23, 2008 Share Posted September 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125509-solved-include-in-while-loop/#findComment-648892 Share on other sites More sharing options...
Zeradin Posted September 23, 2008 Author Share Posted September 23, 2008 <?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'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/125509-solved-include-in-while-loop/#findComment-648894 Share on other sites More sharing options...
Zeradin Posted September 23, 2008 Author Share Posted September 23, 2008 you were right it was overwriting the query/result/info variables. i didn't know it carried through like that but now that i think about it, it just inserts the code so why wouldn't it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/125509-solved-include-in-while-loop/#findComment-648897 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.