Warning: Invalid argument supplied for foreach() in ? Help

Hello

Why am I getting a PHP Warning: Invalid argument supplied for foreach()



$sql="select id,ip,port from rtv where country='$cron_id' and active='1' order by id";
	$result = mysql_query($sql) or die("MYSQL ERROR: $sql");
	$numrows = mysql_num_rows($result);
	for($x=0;$x<$numrows;$x++){
	$resrow = mysql_fetch_row($result);
	$id = $resrow[0];
	$cron_rip = $resrow[1];
	$cron_rport = $resrow[2];
	
	$authid[$id] = $id;
	$cron_ip[$id] = $cron_rip;
	$cron_port[$id] = $cron_rport; 
	
}

foreach($cron_ip as $i => $servers)
	{
	$fp = @fsockopen($cron_ip[$i],$cron_port[$i],$errno,$errstr,4);
	if (!$fp) 
		{ 
		$listeners[$i] = "0";
		$msg[$i] = "server offline";   # ERROR [Connection refused / Server down]
		$error[$i] = "1";
		/* SERVER OFFLINE */
		$sql = "update rtv set info='0|0|0|0|offline', pozicija='0' where id='$authid[$i]'";
		$result = mysql_query($sql) or die("ERROR: $sql");
		} 
	else

put var_dump($cron_ip, $cron_port); before your foreach and give us the output.

array(22) { [1]=> string(13) "78.129.199.49" [2]=> string(13) "78.129.199.49" [3]=> string(13) "78.129.199.49" [4]=> string(12) "67.15.73.219" [5]=> string(12) "67.15.73.219" [7]=> string(13) "85.25.100.218" [9]=> string(22) "streaming.tdiradio.com" [28]=> string(22) "free.freeshoutcast.com" [30]=> string(12) "77.105.36.58" [31]=> string(13) "212.72.100.23" [34]=> string(12) "91.121.52.62" [37]=> string(12) "media017.net" [39]=> string(12) "91.121.52.62" [104]=> string(22) "desetka.exyustream.com" [106]=> string(21) "streaming.radiojat.rs" [119]=> string(23) "streaming8.tdiradio.com" [127]=> string(17) "radioas.kbcnet.rs" [128]=> string(12) "217.24.17.31" [130]=> string(17) "live4.okradio.net" [153]=> string(13) "rtvpancevo.rs" [173]=> string(14) "87.106.136.203" [177]=> string(15) "213.239.205.210" } array(22) { [1]=> string(5) "12100" [2]=> string(5) "12200" [3]=> string(5) "12300" [4]=> string(5) "16000" [5]=> string(5) "30000" [7]=> string(5) "10200" [9]=> string(4) "9090" [28]=> string(5) "60026" [30]=> string(4) "8879" [31]=> string(4) "8400" [34]=> string(4) "8184" [37]=> string(4) "8034" [39]=> string(4) "8016" [104]=> string(2) "80" [106]=> string(5) "12121" [119]=> string(5) "13131" [127]=> string(4) "8020" [128]=> string(4) "8102" [130]=> string(4) "8052" [153]=> string(4) "7777" [173]=> string(4) "9400" [177]=> string(4) "6052" } 

based on that, I’m not sure why you are receiving a warning about the foreach statement. You definitely have a valid array. Did you get a warning with the above var_dump()?

no :frowning: that make me crazy

:slight_smile: Thank you cpradio
you are right i have found some header errors.
website works great now! thank you.