array keys
Posted: Sun Nov 19, 2006 10:31 am
I haven't written any php in a while and the result is that now I'm beating myself up because I can't figure out why I can't pull the results out of a simple mysql db query. Does anyone see what I'm doing wrong?:
Thanks
Code: Select all
$query = "SELECT DISTINCT
artist
FROM recordings
ORDER BY rand()
LIMIT $num"; // when I run this query from querybrowser it works
$res = mysql_query($query);
print("numrows=" . mysql_num_rows($res)); // prints the correct number
print("<br/>");
//print_r($res); // this prints "Resource id#"
// if results, print link
if(isset($res)) // also tried if(mysql_num_rows($res) != 0)
{
echo "\n<table class=\"cloud\">";
for($i = 0; $i < $h; $i++)
{
echo "\n\t<tr>";
for($j = 0; $j < $w; $j++)
{
$rows = mysql_num_rows($res); //confirms that I am getting the correct # of rows
echo "\n\t\t<td><a href=\"\">-> ".$res[$i][0]."</a></td>\n"; // Here is where the problem liies, I think. $res[$i][0] doesn't print anything I've also tried a few other things
}
print("\n\t</tr>");
}
echo "\n</table><br/><br>";
}