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!
Moderator: General Moderators
anthony88guy
Forum Contributor
Posts: 246 Joined: Thu Jan 20, 2005 8:22 pm
Post
by anthony88guy » Fri May 06, 2005 3:16 pm
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?
Last edited by
anthony88guy on Thu May 12, 2005 5:55 pm, edited 3 times in total.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri May 06, 2005 3:41 pm
where does $mysa and $myarmysize come from?
Have you tried echo'ing out your query to see if its the expected result?
anthony88guy
Forum Contributor
Posts: 246 Joined: Thu Jan 20, 2005 8:22 pm
Post
by anthony88guy » Fri May 06, 2005 3:53 pm
The $mysa and $myarmysize are coming from a form.
print $mysa . "<br>"; = 149502930
print $myarmysize . "<br>"; = 1114
print $query; = Resource id #8
aaroncampbell
Forum Newbie
Posts: 4 Joined: Thu Mar 04, 2004 11:50 am
Post
by aaroncampbell » Fri May 06, 2005 4:01 pm
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.
anthony88guy
Forum Contributor
Posts: 246 Joined: Thu Jan 20, 2005 8:22 pm
Post
by anthony88guy » Fri May 06, 2005 4:13 pm
SELECT * FROM `farms` WHERE defenceaction < '149502930' AND armysize > '1114' ORDER BY `time` ASC
I dont see anything wrong with the query?
aaroncampbell
Forum Newbie
Posts: 4 Joined: Thu Mar 04, 2004 11:50 am
Post
by aaroncampbell » Fri May 06, 2005 5:44 pm
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.
anthony88guy
Forum Contributor
Posts: 246 Joined: Thu Jan 20, 2005 8:22 pm
Post
by anthony88guy » Fri May 06, 2005 6:29 pm
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.