Page 1 of 1

Searching Error [Solved]

Posted: Fri May 06, 2005 3:16 pm
by anthony88guy
I am using the query to search my database.

Code: Select all

$query = mysql_query("SELECT * FROM `farms`
WHERE defence < '$sa'
AND armysize > '$armysize'
ORDER BY `time` ASC") or die(mysql_error());


My problem is that when I search the database I get no results when I should. For example:

$sa = 149502930
$armysize = 1114

The defence of someone in the database is: 46372141
and their armysize: 31442

The query should search the database for anyone that has a defence action less then "149502930", and a armysize greater then "1114". Any suggestions?

Posted: Fri May 06, 2005 3:41 pm
by John Cartwright
where does $mysa and $myarmysize come from?
Have you tried echo'ing out your query to see if its the expected result?

Posted: Fri May 06, 2005 3:53 pm
by anthony88guy
The $mysa and $myarmysize are coming from a form.

print $mysa . "<br>"; = 149502930
print $myarmysize . "<br>"; = 1114
print $query; = Resource id #8

Posted: Fri May 06, 2005 4:01 pm
by aaroncampbell
Do this:

Code: Select all

$q = "SELECT * FROM `farms` WHERE defenceaction < '$mysa' AND armysize > '$myarmysize' ORDER BY `time` ASC";
echo $q;
$query = mysql_query($q) or die(mysql_error());
That way, you see the exact query just before it runs. It will probably help you see the problem.

Posted: Fri May 06, 2005 4:13 pm
by anthony88guy
SELECT * FROM `farms` WHERE defenceaction < '149502930' AND armysize > '1114' ORDER BY `time` ASC
I dont see anything wrong with the query?

Posted: Fri May 06, 2005 5:44 pm
by aaroncampbell
well, does pasting that SAME query into phpMyAdmin work? If not, what is the error. If so, your db connection in your script is broke.

Posted: Fri May 06, 2005 6:29 pm
by anthony88guy
Yes I pasted the same query and no go. Although I realised something after testing different variables. If $mysa = 11 and defenceaction = 2,

defenceaction < '$mysa'

That wouldn't work because it see's defenceaction as being bigger then $mysa.

Just looked up mysql numeric column types, and changed varchar to bigint, and no it works.