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!
Hey, I keep getting an error when i try and load this page. It keeps saying "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in **********************"
That's because inside your function lookup() the resource variable $result is undefined. It is outside of the scope of your function. You either have to put the mysql_query inside the function or pass the variable pointing to the results.
By the way instead of just looping through all of the table looking for one item, you can get the database to find it for you, which is much more optimized. Look into using the WHERE clause in mysql....something like this:
SELECT * from test WHERE id='$wanted'
Last edited by Eric! on Tue Aug 31, 2010 6:07 pm, edited 3 times in total.
So, I tried doing what you suggested and I'm still getting the same error, even with the mysql_query inside the function.
Errors:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/s/c/s/scssalesweb/html/Streetmate2005Group1test.php on line 10
$wanted = 0;
function lookup($wanted) //Part number of the item this form is for.
{
$result = mysql_query("SELECT * FROM test WHERE $id=$wanted");
while ($row = mysql_fetch_assoc(result))
{
$price = $row['price'];
}
}
?>
$wanted = NULL;
function lookup($wanted) //Part number of the item this form is for.
{
$result = mysql_query(SELECT * from test WHERE id='$wanted');
while($row = mysql_fetch_assoc($result))
{
$price = $row['price'];
}
}