Code: Select all
Warning: Invalid argument supplied for foreach() in /home/virtual/site13/fst/var/www/html/update.php on line 20Code: Select all
foreach ($id as $kay => $val) {Moderator: General Moderators
Code: Select all
Warning: Invalid argument supplied for foreach() in /home/virtual/site13/fst/var/www/html/update.php on line 20Code: Select all
foreach ($id as $kay => $val) {Code: Select all
if (is_array($myarray)) foreach ($myarray as $idx => $value) {
# do stuff
}
else {
die ('You motherless son of a goat, that''s not an array!');
# PS: Above Phrase is copyright Monty Python :)
}Code: Select all
<?PHP
include("includes/dbs.php");
$lk = mysql_connect($serv,$user,$pass) or die (mysql_error());
mysql_select_db($dbname[0],$lk);
$qur = "select * from News order by id desc limit 4";
$res = mysql_query($qur) or die (mysql_error());
while ($row = mysql_fetch_assoc($res)) {
$id[] = $row["id"];
$tit[] = $row["title"];
$bod[] = $row["body"];
$time[] = $row["time"];
$date[] = $row["date"];
$by[] = $row["byhow"];
}
?>
<html>
<body bgcolor="#C0C0C0"
style="color: #FFFFFF; text-align: right; font-weight: bold; margin-top: 0; margin-bottom: 0">
<?PHP
foreach ($id as $kay => $val) {
if ($by[$kay] == "forgun") {
?>
<a href="mailto:webmaster@il-vortex.net">
<img border="0"
src="images/staff/forgun.gif" style="border: 3px double #0000FF"></a>
<?
}
if ($by[$kay] == "chef") {
?>
<a href="mailto:webmaster@il-vortex.net">
<img border="0"
src="images/staff/chef.gif" style="border: 3px double #0000FF"></a>
<?
}
?>probably the condition is never fulfilled and therefor the array is undefined when it comes to foreach. You can avoid that (and a warning message) by defining all arrays before the first usewhile ($row = mysql_fetch_assoc($res)) {
Code: Select all
$id = $tit = $bod = $time = $date = $by = array();
$qur = "select * from News order by id desc limit 4";
$res = mysql_query($qur) or die (mysql_error());
while ($row = mysql_fetch_assoc($res)) {
$id[] = $row["id"];
$tit[] = $row["title"];
$bod[] = $row["body"];
$time[] = $row["time"];
$date[] = $row["date"];
$by[] = $row["byhow"];
}