Foreach Array Loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Foreach Array Loop

Post 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>";
}
}
?>
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post 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>";
}
} 
?>
Post Reply