Jump to content

not sure what to call this


quickstopman

Recommended Posts

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

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?

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 !

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)) {
}
}

?>

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>

 

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>';
}
}

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.