quickstopman Posted January 21, 2008 Share Posted January 21, 2008 how to make a while statement in side of an if statement heres what im trying todo <?php $friends = mysql_query("SELECT * FROM friends WHERE friend = '{$_SESSION['id']}' ") or die(mysql_error()); if($friends == '') { $friends2 = mysql_query("SELECT * FROM friends WHERE friends_with = '{$_SESSION['id']}' ") or die(mysql_error()); while ($list = mysql_fetch_array($friends2)) { } else { while ($list = mysql_fetch_array($friends)) { } ?> Link to comment https://forums.phpfreaks.com/topic/87024-not-sure-what-to-call-this/ Share on other sites More sharing options...
quickstopman Posted January 21, 2008 Author Share Posted January 21, 2008 how to make a while statement in side of an if statement heres what im trying todo <?php $friends = mysql_query("SELECT * FROM friends WHERE friend = '{$_SESSION['id']}' ") or die(mysql_error()); if($friends == '') { $friends2 = mysql_query("SELECT * FROM friends WHERE friends_with = '{$_SESSION['id']}' ") or die(mysql_error()); while ($list = mysql_fetch_array($friends2)) { } else { while ($list = mysql_fetch_array($friends)) { } ?> in fact is it even possible? Link to comment https://forums.phpfreaks.com/topic/87024-not-sure-what-to-call-this/#findComment-445025 Share on other sites More sharing options...
pdkv2 Posted January 21, 2008 Share Posted January 21, 2008 how to make a while statement in side of an if statement heres what im trying todo <?php $friends = mysql_query("SELECT * FROM friends WHERE friend = '{$_SESSION['id']}' ") or die(mysql_error()); if($friends == '') { $friends2 = mysql_query("SELECT * FROM friends WHERE friends_with = '{$_SESSION['id']}' ") or die(mysql_error()); while ($list = mysql_fetch_array($friends2)) { } else { while ($list = mysql_fetch_array($friends)) { } ?> in fact is it even possible? I dont thik so ! Link to comment https://forums.phpfreaks.com/topic/87024-not-sure-what-to-call-this/#findComment-445026 Share on other sites More sharing options...
adam291086 Posted January 21, 2008 Share Posted January 21, 2008 why don't you just do <?php if($friends == '') { $friends2 = mysql_query("SELECT * FROM friends WHERE friends_with = '{$_SESSION['id']}' ") or die(mysql_error()); while ($list = mysql_fetch_array($friends2)) { } } else { $friends = mysql_query("SELECT * FROM friends WHERE friend = '{$_SESSION['id']}' ") or die(mysql_error()); { while ($list = mysql_fetch_array($friends)) { } } ?> Link to comment https://forums.phpfreaks.com/topic/87024-not-sure-what-to-call-this/#findComment-445027 Share on other sites More sharing options...
rajivgonsalves Posted January 21, 2008 Share Posted January 21, 2008 what exactly your trying to achieve by these loops ? Link to comment https://forums.phpfreaks.com/topic/87024-not-sure-what-to-call-this/#findComment-445028 Share on other sites More sharing options...
quickstopman Posted January 21, 2008 Author Share Posted January 21, 2008 well im trying to grab what friends a user has but in the mysql statement when ever i try to find `friend` and `friends_with` i don't get anything but if i use OR i only 1 user can see who they're friends with so i was trying to find alternatives heres the code <?php if($_GET['type'] == '') { header("location:http://www.socialgrabbr.com/friends.php?type=view"); } if (isset($_GET['type']) && $_GET['type'] == 'view') { $friends = mysql_query("SELECT * FROM friends WHERE friend = '{$_SESSION['id']}' OR friends_with = '{$_SESSION['id']}' ") or die(mysql_error()); while ($list = mysql_fetch_array($friends)) { ?> <table width="" cellspacing="5px"> <tr> <?php if ($list['accepted'] == 'yes') { $friend_info = mysql_query("SELECT * FROM users WHERE id ='{$list['friend']}'") or die(mysql_error()); $friend = mysql_fetch_array($friend_info); echo "<td width='100px' class='link'>"; echo "<a href='http://www.socialgrabbr.com/profile.php?profile_id=". $friend['id'] ."'<img class='img' maxwidth='200px' maxheight='200px' src='". $friend['img'] ."'></a><br /><br />". $friend['username'] ."\n"; echo "</td>"; } else { echo ""; } } ?> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/87024-not-sure-what-to-call-this/#findComment-445036 Share on other sites More sharing options...
rajivgonsalves Posted January 21, 2008 Share Posted January 21, 2008 I assume that the friends_with is the field name holding the id of the person logged in ? Link to comment https://forums.phpfreaks.com/topic/87024-not-sure-what-to-call-this/#findComment-445046 Share on other sites More sharing options...
rajivgonsalves Posted January 21, 2008 Share Posted January 21, 2008 I cleant up the code a bit this should do it if($_GET['type'] == '') { header("location:http://www.socialgrabbr.com/friends.php?type=view"); } if (isset($_GET['type']) && $_GET['type'] == 'view') { $friends = mysql_query("SELECT * FROM friends WHERE friends_with = '{$_SESSION['id']}' ") or die(mysql_error()); while ($list = mysql_fetch_array($friends)) { echo '<table width="" cellspacing="5px"><tr>'; if ($list['accepted'] == 'yes') { echo "<td width='100px' class='link'>"; echo "<a href='http://www.socialgrabbr.com/profile.php?profile_id=". $list['id'] ."'><img class='img' maxwidth='200px' maxheight='200px' src='". $list['img'] ."'></a><br /><br />". $list['username'] ."\n"; echo "</td>"; } echo '</tr></table>'; } } Link to comment https://forums.phpfreaks.com/topic/87024-not-sure-what-to-call-this/#findComment-445053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.