hi all,
I've got a code problem. Basically, I want to use a common function to retrieve a recordset from a MySQL database.
Here's the current code:
<?php
function sqlQuery($select="", $from="", $where="")
{
$dbcnx = mysql_connect("db.phastings.co.uk:3306", "**", "**");
mysql_select_db("database1");
$webpages_recordset = mysql_query($select . $from . $where);
if (!$webpages_recordset) {
echo("</TABLE>");
echo("<P>Error retrieving webpages for the selected website!<BR>".
"Error: " . mysql_error());
exit();
}
else {
return $webpages_recordset;
}
}
?>
elsewhere in the .php file, I call the function, like so:
<?php // Define the query and send to function to be processed.
// The basic SELECT statement
$aa = " SELECT DISTINCT webpage_id, title";
$bb = " FROM webpage";
$cc = " WHERE webpage_id > 0";
sqlQuery($aa, $bb, $cc);
?>
Then output, like this:
<?php
while ($webpage = mysql_fetch_array($webpages_recordset)){ // loop through each webpage within the webpages_recordset.
... // blah blah blah
}
The page reporting the following error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
I therefore suspect, I'm not returning '$webpages_recordset;' in the correct format. Does anyone know if this asumption is correct, or whereby I might otherwise have an error?
Many thanks.