Okay, I have a function in my php page to do a quick database lookup based on the id number passed to it.
When the function is uncommented, it tells my that my $db variable is undefined. When I uncomment it, it throws no error. I'm using this $db variable in other queries on the same page. This is odd. Here's my relevant code:
<?php
include('./db.php');
// this includes the database connection info, putting it into a nice variable, $db, that I use to reference in my mysql_query() calls in the same page.
// general mysql_query() call with $db passed, and it works fine. Then I declare my function:
funtion getArtistCount($artistID)
{
$query = "SELECT COUNT(*) FROM master_list WHERE artistID = '$artistID'";
$result = mysql_query($query, $db) or die(mysql_error());
$row = mysql_fetch_row($result);
return $row[0];
}
When the above code is run, I get notices that $db is undefined, then more errors that the resource $db isn't valid, blah, blah, blah.
So my question is why isn't the variable $db working inside the function when it's working outside? Something to do with definition or something? Someone care to throw me a bone here? Thanks, guys.
James