Jump to content

mysql count rows


uwannadonkey

Recommended Posts

<?php
include('inc/header.php');

echo"--- Food---<br>";


$result=mysql_query('SELECT * FROM food WHERE owner = $user->ID and name = Apple'); 
if (mysql_num_rows($result) >= 1)
{
$apple = mysql_num_rows($result);
echo " Apples($apple)";
}









include('inc/footer.php');
?>

 

thats the code for counting apples, but this comes out:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/trukki4/public_html/averyel/inventory.php on line 8

Link to comment
Share on other sites

silly me i should of noticed, you are using ' quotes instead of " for your query, you cannot include $variables without concatenating with single quotes, you have 2 options:

 

either:

 

$result=mysql_query("SELECT * FROM food WHERE owner = $user->ID and name = Apple"); 

 

or concatenate:

 

$result=mysql_query('SELECT * FROM food WHERE owner = '.$user->ID.' and name = Apple'); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.