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
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?

Link to comment
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?

 

I dont thik so !

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.