Jump to content

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
https://forums.phpfreaks.com/topic/91683-mysql-count-rows/
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
https://forums.phpfreaks.com/topic/91683-mysql-count-rows/#findComment-469563
Share on other sites

Unknown column 'Apple' in 'where clause'

 

but there is a column apple..

 

this is a copy of the mysql table:

ID  owner  name  effect  bonus

1 1             Apple 5 energy

2 1             Apple 2 energy

3 1               Apple 5 energy

Link to comment
https://forums.phpfreaks.com/topic/91683-mysql-count-rows/#findComment-469572
Share on other sites

fixed

 

$apple1= Apple;

$result=mysql_query("SELECT * FROM food WHERE owner = $user->ID AND name = 'Apple'")or die(mysql_error()); 

if (mysql_num_rows($result) >= 1)

{

$apple = mysql_num_rows($result);

echo " Apples($apple)";

}

 

apple needed a 'apple' to work

Link to comment
https://forums.phpfreaks.com/topic/91683-mysql-count-rows/#findComment-469583
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.