tobyheywood
IS-IT--Management
Hi all,
I'm using Apache/2.0.47 (Win32) PHP/4.3.3 and for some very bizzare reason seem to be experiencing problems with foreach() statements.
The really weird thing is that it worked until I emptied the database that the info is being pulled from, now I have repopulated the database it still isn't working.
Can anyone make a suggestion as to why and also if you can suggest any better ways writing the above script it would be greatly appreciated.
TIA
Toby Heywood
I'm using Apache/2.0.47 (Win32) PHP/4.3.3 and for some very bizzare reason seem to be experiencing problems with foreach() statements.
Code:
$user = "username";
$pass = "password";
$loca = "localhost";
$datb = "web";
$link = mysql_connect($loca, $user, $pass);
if(! $link)
die(mysql_error());
mysql_select_db($datb, $link)
or die(mysql_error());
$queryrows = "SELECT * FROM quotes";
$result = mysql_query($queryrows, $link);
$rows = mysql_num_rows($result);
$randomid = rand(1,$rows);
// above all works to generate random id
$query = "SELECT quote FROM quotes where id = $randomid";
$result = mysql_query($query, $link);
$field = mysql_fetch_row($result);
foreach($field as $fact)
print "<p class=\"body\"><marquee>$fact</marquee></p>";
mysql_close($link);
The really weird thing is that it worked until I emptied the database that the info is being pulled from, now I have repopulated the database it still isn't working.
Can anyone make a suggestion as to why and also if you can suggest any better ways writing the above script it would be greatly appreciated.
TIA
Toby Heywood