Page 1 of 1
Multiple id numbers
Posted: Wed Sep 08, 2010 1:41 pm
by Scoobs
Been reading all over the web for days and haven't found a simple solution.
I took this part of a working file
$res = mysql_query("SELECT itemid FROM useritems WHERE userid = ". sqlesc($me[id]) ." ORDER BY itemid ASC");
And changed it to this
$res = mysql_query("SELECT id, itemid FROM useritems WHERE userid = ". sqlesc($me[id]) ." AND itemid = 23");
Great, now I can see this one item on my inventory !
But what I really need it to do is to show x amount of id#s in my inventory
so I tried the simple approach
$res = mysql_query("SELECT id, itemid FROM useritems WHERE userid = ". sqlesc($me[id]) ." AND itemid = 23",24,25,26);
It does not work even after trying it 10 different ways ...
itemid =("23", "24", "25", "26"); and so on
Any help would be highly appreciated !
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 1:48 pm
by AbraCadaver
You either need full expressions ORed together or use IN, or BETWEEN if it is a range:
[text]AND (itemid = "23" OR itemid = "24" OR itemid = "25" OR itemid = "26")[/text]
--or--
[text]AND itemid IN ("23", "24", "25", "26")[/text]
--or--
[text]AND (itemid BETWEEN 23 AND 26)[/text]
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 2:00 pm
by Scoobs
Thanks for a fast reply
Although it doesnt like none of them:p
unexpected T_LNUMBER
Ill share more of the file if it helps any, Thanks again
$res = mysql_query("SELECT id, itemid FROM useritems WHERE userid = ". sqlesc($me[id]) ." AND itemid = 26");
while ($row = mysql_fetch_array($res)) {
$miscitems[] = $row[itemid];
$indexid[$row[itemid]] = $row[id];
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 2:06 pm
by AbraCadaver
Scoobs wrote:Thanks for a fast reply
Although it doesnt like none of them:p
unexpected T_LNUMBER
Ill share more of the file if it helps any, Thanks again
$res = mysql_query("SELECT id, itemid FROM useritems WHERE userid = ". sqlesc($me[id]) ." AND itemid = 26");
while ($row = mysql_fetch_array($res)) {
$miscitems[] = $row[itemid];
$indexid[$row[itemid]] = $row[id];
That's a PHP error. What is the full code and what line number does the error state? Aren't you missing a closing } in the while loop?
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 2:29 pm
by Scoobs
$res = mysql_query("SELECT id, itemid FROM useritems WHERE userid = ". sqlesc($me[id]) ." AND (itemid = "23" OR itemid = "24" OR itemid = "25" OR itemid = "26");
was the line of error with each change I made
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 2:35 pm
by AbraCadaver
Code: Select all
$res = mysql_query("SELECT id, itemid FROM useritems WHERE userid = ". sqlesc($me['id']) ." AND (itemid = '23' OR itemid = '24' OR itemid = '25' OR itemid = '26'");
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 2:40 pm
by Scoobs
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/kingdomr/public_html/research/inventoryEXP.php on line 178
This is line 178... while ($row = mysql_fetch_array($res)) {
$res = mysql_query("SELECT id, itemid FROM useritems WHERE userid = ". sqlesc($me['id']) ." AND (itemid = '23' OR itemid = '24' OR itemid = '25' OR itemid = '26'");
while ($row = mysql_fetch_array($res)) {
$miscitems[] = $row[itemid];
$indexid[$row[itemid]] = $row[id];
Also I pm you .
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 2:53 pm
by AbraCadaver
Code: Select all
$res = mysql_query("SELECT id, itemid FROM useritems WHERE userid = '". sqlesc($me['id']) ."' AND (itemid = '23' OR itemid = '24' OR itemid = '25' OR itemid = '26')") or die(mysql_error());
Plus, you were missing the closing ) inside the query.
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 2:59 pm
by Scoobs
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1'' AND (itemid = '23' OR itemid = '24' OR itemid = '25' OR itemid = '26')' at line 1
line 1 is just
<?php
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 3:10 pm
by AbraCadaver
You need to get your quotes sorted out. What I posted last should work if you copy and paste it. It may also depend on what $me['id'] is and what sqlesc() does to it.
Re: Multiple id numbers
Posted: Wed Sep 08, 2010 3:21 pm
by Scoobs
Well thanks for the help, will continue to try everything, till I get it