Page 1 of 1

Foreach Array Loop

Posted: Thu Dec 25, 2003 11:25 am
by Straterra
I have this code..yet, it returns the error Invalid Argument Supplied For Foreach. This is the code....

Code: Select all

<?php
$dbname = 'eckbios';
if ($db = sqlite_open($dbname, 0666, $sqliteerror)){
$users = (sqlite_query($db, "SELECT socomname from clanprofile ORDER BY socomname"));
foreach ( $users as $val ) {
?>
<a href="
<?php
echo "pro.php?user=$val";
?>
">
<?php
echo "$val";
?>
</a>
<?php
echo "<br><br>";
}
}
?>

Posted: Thu Dec 25, 2003 1:49 pm
by aquila125
sqlite_query returns a resource, not an array...
this is how it should be:

Code: Select all

<?php
$dbname = 'eckbios';
if ($db = sqlite_open($dbname, 0666, $sqliteerror)){
$result = (sqlite_query($db, "SELECT socomname from clanprofile ORDER BY socomname"));
while ($row=sqlite_fetch_array($result) {
?>
<a href="
<?php
echo "pro.php?user=".$row['socomname'];
?>
">
<?php
echo $row['socomname'];
?>
</a>
<?php
echo "<br><br>";
}
} 
?>