Jump to content

Infinite loop issue I'm guessing.


GB_001

Recommended Posts

<?php
session_start();
include('Connect.php');

$User=$_SESSION['email'];
$resulter = mysql_query("SELECT * FROM Friends WHERE (user='$User' AND pending=0) OR (friend='$User' AND pending=0) ")or die(mysql_error());


while($rowf=mysql_fetch_array($resulter) or die(mysql_error()))

{
$po1=$rowf['user'];
$po2=$rowf['friend']
if($po1==$User)
{
$Friend=$po2;
}else
{
$Friend=$po1;
}
$resultn = mysql_query("SELECT * FROM News WHERE Who='$Friend' LIMIT 1")or die(mysql_error());
$rown=mysql_fetch_array($resultn) or die(mysql_error());
$N3=$rown['Who'];
$N1=$rown['What'];
$N2=$rown['Time'];

echo"$N3 $N1 $N2<br>";
}

?>

 

For some reason the code does not work, I even tried to echo something at the end to see if it's an infinite loop and it didn't echo, so I'm guessing it is. Please help.

-GB

Link to comment
Share on other sites

Also don't copy variables when you don't need to, you waste memory that way. Sure its not a problem for a mom and pop site, but it's better to not learn bad habits!

 


<?php

session_start ();

include 'Connect.php';

$resulter = mysql_query ( "SELECT * FROM Friends WHERE user = '" . $_SESSION['email'] . "' AND pending = 0 OR friend = '" . $_SESSION['email'] . "' AND pending = 0;" ) or die ( mysql_error () );

if ( mysql_num_rows ( $resulter ) > 0 )
{
while ( $rowf = mysql_fetch_assoc ( $resulter ) )
{
	if ( $rowf['user'] == $_SESSION['email'] )
	{
		$Friend = $rowf['friend'];
	}
	else
	{
		$Friend = $rowf['user'];
	}

	$resultn = mysql_query ( "SELECT * FROM News WHERE Who = '" . $Friend . "' LIMIT 1;" ) or die ( mysql_error () );

	if ( mysql_num_rows ( $resultn ) > 0 )
	{
		echo $rown['Who'] . ' ' . $rown['What'] . ' ' $rown['Time'] . '<br>';
	}
}
}

?>

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.