Page 1 of 1

Printing rows from a table, and the foreach loop

Posted: Fri Dec 17, 2004 8:31 am
by TheOracle
Hi All,

I am trying to get some data from a table to display as hyperlinks within a html table, and am having some problems.

I'm getting the following error:

Code: Select all

invalid argument supplied for foreach()
Here is my code

Code: Select all

function writeList()
	{
	$result=mysql_query("select * from ws_basic order by site_name") or die(mysql_error());
	$list=mysql_fetch_array($result);
	echo "<tr>\n";
	echo "<td align='center'>Current Web Servers</td>\n";
	foreach($list as $record)
		{
		echo "<tr>\n";
		echo "<td><a href="ws_update_detail.php?siteid=$record[server_no]&".SID."">".html($record[site_name])."</a></td>\n";
		echo "</tr>\n";
		}
	}
Can someone suggest what is wrong, or a different way to approach it?

Many thanks

Posted: Fri Dec 17, 2004 8:53 am
by []InTeR[]
use
while($list = mysql_fetch_array($result))
instead of foreach.

And the $record[site_name] doesn't exist.
Use $list['site_name'];