Multiple id numbers

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

Post Reply
Scoobs
Forum Newbie
Posts: 8
Joined: Wed Sep 08, 2010 1:21 pm

Multiple id numbers

Post 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 !
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Multiple id numbers

Post 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]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Scoobs
Forum Newbie
Posts: 8
Joined: Wed Sep 08, 2010 1:21 pm

Re: Multiple id numbers

Post 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];
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Multiple id numbers

Post 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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Scoobs
Forum Newbie
Posts: 8
Joined: Wed Sep 08, 2010 1:21 pm

Re: Multiple id numbers

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Multiple id numbers

Post 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'");
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Scoobs
Forum Newbie
Posts: 8
Joined: Wed Sep 08, 2010 1:21 pm

Re: Multiple id numbers

Post 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 .
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Multiple id numbers

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Scoobs
Forum Newbie
Posts: 8
Joined: Wed Sep 08, 2010 1:21 pm

Re: Multiple id numbers

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Multiple id numbers

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Scoobs
Forum Newbie
Posts: 8
Joined: Wed Sep 08, 2010 1:21 pm

Re: Multiple id numbers

Post by Scoobs »

Well thanks for the help, will continue to try everything, till I get it
Post Reply