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
https://forums.phpfreaks.com/topic/144853-infinite-loop-issue-im-guessing/
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>';
	}
}
}

?>

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.