Not quite sure why this isn't working

I am trying to select from the db an id where X is divisble by Y.

Here is the code that I have, and isn’t working at all:

[php]$rres = @mysql_query(“SELECT id,theodds FROM odds WHERE (’$totalclaimed’%theodds==0) ORDER BY RAND() LIMIT 1”);
$rrow=@mysql_fetch_array($rres);
$position=$rrow[“id”];[/php]

$totalclaimed is already defined and is defined correctly, I verified that it works.

id & theodds are column names in the table ‘odds’

I am sure it is something simple, but I have sat on this for a while now without a solution, and help would be greatly appreciated.

Thanks!

[php]
$rres = mysql_query(“SELECT id,theodds FROM odds WHERE $totalclaimed % theodds=0 ORDER BY RAND() LIMIT 1”);
$rrow=mysql_fetch_array($rres);
$position=$rrow[“id”];
[/php]

Its going to have a problem with the where clause. I’m not really sure what you’re trying to do with $totalclaimed, but to use it there, you have to tell it what its supposed to equal or not equal, get rid of the percent sign and replace with ANd or OR.

Well no he wants to see if the value is divisible. For example

SELECT 200 % 2;

Result is 0 means it’s divisible by 2.

SELECT 201 % 2

Result is 1 means it’s not divisible by 2.

So using WHERE field % 2 = 0 is valid.

plintu just converted his string to an integer and removed the invalid double equals, which should work.

you are absolutely right, the main error was in the double equal sign, DOUBLE EQUAL SIGNS ARE PHP NOT MYSQL!!!
Do not use them in mysql queries! You can use double and triple equal signs in php for comparing but it is improper syntax in mysql.
I removed the single quotes because they are used for strings not for singular numbers! I would only gather that he is trying to see what NUMBER in the $totalclaimed variable is divisible by a number in the theodds varibable.
no string no quotes
as for the parenthesis they were not needed there was not multiple conditions that needed to be met
example:
[php]
SELECT id,theodds FROM odds WHERE ($totalclaimed % theodds=0 AND $totalclaimed>3) ORDER BY RAND() LIMIT 1");
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service