We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Specific ID's to be pulled out; SQL
Topic Started: Mar 16 2005, 10:38 AM (332 Views)
SkItZo
Support Volunteer
[ *  *  * ]
I have this script of which an SQL command is executed. It's taking data from "ranks" table I have. Now, the problem is, I only want a certain few members to be shown at this page of where the SQL command is executed. There isn't a seperate "usergroup" table, but there is a "rank_id" field at the members table. I know for sure that it's the one deciding on which usergroup you are. So, I'm wondering, how can I pull data from that table from members only having a rank_id of '1,2,3,4,101''

Here's the current code:

Code:
 
$result2 = mysqlquery("$mysql_database", "SELECT * FROM ranks WHERE RANK_ID = '$rank'");
Offline Profile Quote Post Goto Top
 
Stefan
Member Avatar
Mew?
[ *  *  *  *  *  *  * ]
Code:
 
SELECT * FROM ranks WHERE RANK_ID BETWEEN '1' AND '4' OR RANK_ID = '101'

Maybe? :unsure:

[/SQL newb]
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
Maybe instead of in the query, put it in the variable.

Quote:
 

$rank1 = 1;
$rank2 = 2;
$rank3 = 3;
$rank4 = 4;
$rank5 = 101;


Then for the query

Quote:
 
$result2 = mysqlquery("$mysql_database", "SELECT * FROM ranks WHERE RANK_ID = '$rank1','$rank2',$rank3','$rank4',$rank5'");


:ermm:

That may hopefully work. I'm pretty new to this as well.
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
you use phpmyadmin? if so use that to make the code for you, using the server side seacrh function
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Silly rabbits, use IN().

Code:
 
$result2 = mysql_query("$mysql_database", "SELECT * FROM ranks WHERE rank_id IN(1,2,3,4,101)");
Offline Profile Quote Post Goto Top
 
Mez
Zetaboards: now RFC2324 Compliant
[ *  *  *  * ]
Seth
March 16, 2005 01:06 PM
Silly rabbits, use IN().

Code:
 
$result2 = mysql_query("$mysql_database", "SELECT * FROM ranks WHERE rank_id IN(1,2,3,4,101)");

glad someone posted that - I was about to go on a slapping spree.

Yeah, the IN() function is your best call :D It's very useful for just selecting certain Id's :D
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply