DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • November 19, 2018, 03:04:41 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1] 2   Go Down
  Print  
Author Topic: SQL Queries for Dummies  (Read 5273 times)
0 Members and 1 Guest are viewing this topic.
Zanzaras
Captain of the Guard
***
Offline Offline

Posts: 220


*Snipe*


View Profile
« on: September 08, 2005, 12:39:48 PM »

I need a little shove in the right direction. I know absoulutely nothing about sql queries, so this will probably be laughably simple to some of you guys/gals out there.

I need to run a query to find all the players who are members of a particular clan and randomly choose one of them.

Any help that anyone can give me on this would be greatly appreciated. I'll take anything from the actual code to a "there's a pretty good example of how to do this in such-such module".

Thanks!
« Last Edit: September 08, 2005, 12:40:26 PM by Zanzaras » Logged

"Intelligence is like a river, the deeper it is the less noise it makes."
Talisman
Administrator
Mod God
*****
Offline Offline

Posts: 5479



View Profile WWW
« Reply #1 on: September 08, 2005, 12:46:16 PM »

Why not take a look in the clans module itself?  There's a query there that shows the member list of each clan.
Logged

Play the latest beta version here on DragonPrime
Nightborn
Guest
« Reply #2 on: September 08, 2005, 12:54:16 PM »

Line 96 should be what you are looking for  Smiley

Logged
Zanzaras
Captain of the Guard
***
Offline Offline

Posts: 220


*Snipe*


View Profile
« Reply #3 on: September 08, 2005, 12:55:33 PM »

Thanks guys... looking at it now.  Wink
Logged

"Intelligence is like a river, the deeper it is the less noise it makes."
Nightborn
Guest
« Reply #4 on: September 08, 2005, 01:01:58 PM »

Code:
   $sql = "SELECT name,login,clanrank,clanjoindate,dragonkills FROM " . db_prefix("accounts") . " WHERE clanid=$detail ORDER BY clanrank DESC,clanjoindate";
   $result = db_query($sql);
        $numberofrowsoftheresult=db_num_rows($result);
   while ($row=db_fetch_assoc($result))
             {
             $current_name=$row['name'];
             }    


Smiley the $sql contains the select query text... if you don't know sql, just read it out to start with... this query -> selects all name,login,clanrank,clanjoindate, dragonkills from the table (with prefix maybe) accounts ... where (conditions) clanid equals $detail (this might be the user entry or so) and is ordered by the field clanrank descending and afterwards by clanjoindate.

db_query starts the select query

db_num_rows lets you know how many rows the query found

db_fetch_assoc reads the results out, row by row. with the while you do things like print every name in a table (like it is in clan.php) or so... you access the fields of a single row via (here) $row['fieldname']

that should be a *little* start. I am also a beginner Sad sorry
Logged
Zanzaras
Captain of the Guard
***
Offline Offline

Posts: 220


*Snipe*


View Profile
« Reply #5 on: September 08, 2005, 02:42:19 PM »

You, sir, are absolutely wonderful!

Thanks for the explaination, that helped a lot!  Grin
Logged

"Intelligence is like a river, the deeper it is the less noise it makes."
Kendaer
Guest
« Reply #6 on: September 08, 2005, 04:09:02 PM »

You can also modify that code to pick a random person in a given clan.

Let assume you already have the clanid of the given clan.

In that case you would want to do
Code:
$query = "select name from ". db_prefix("accounts") where clanid='$clanid' and clanrank > " . CLAN_APPLICANT . " ORDER BY rand(".e_rand().") LIMIT 1";
$res = db_query($sql);
$row = db_fetch_assoc($res);
$name = $row['name'];
Now you have the name of a random clan member who's been accepted into a clan, and you only have one member returned.

The clanrank restriction is so that you don't get people who've merely applied.. If you want to include applicants as well, just remove that 'and clanrank > .....' bit Smiley
« Last Edit: September 08, 2005, 04:09:21 PM by Kendaer » Logged
Zanzaras
Captain of the Guard
***
Offline Offline

Posts: 220


*Snipe*


View Profile
« Reply #7 on: September 10, 2005, 09:22:30 AM »

Thanks Kendaer, that works perfectly!   Cheesy
Logged

"Intelligence is like a river, the deeper it is the less noise it makes."
snehal
Guest
« Reply #8 on: September 14, 2005, 08:06:16 PM »

i want to run one query:- can u say how i can?
list the firstname and lastname of the staff who have not hired any vehicle.
Logged
Talisman
Administrator
Mod God
*****
Offline Offline

Posts: 5479



View Profile WWW
« Reply #9 on: September 14, 2005, 08:11:38 PM »

First AND Last name of staff who have rented VEHICLES?   Huh

Ummm...what game are you doing this in??!?
Logged

Play the latest beta version here on DragonPrime
XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #10 on: September 14, 2005, 09:53:44 PM »

if you google "SQL Queries for Dummies", dragonprime is the first entry... Grin
Logged

Running for more than three years now:
Talisman
Administrator
Mod God
*****
Offline Offline

Posts: 5479



View Profile WWW
« Reply #11 on: September 14, 2005, 09:57:46 PM »

Heh...most people tend to determine what the nature of a site is before posting in it...
Logged

Play the latest beta version here on DragonPrime
XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #12 on: September 14, 2005, 11:00:34 PM »

aaaah... That requires reading...  Tongue  Wink
Logged

Running for more than three years now:
Elessa
Faerie
Mod God
*****
Offline Offline

Posts: 3598


short, sweet and to the point


View Profile
« Reply #13 on: September 14, 2005, 11:06:14 PM »

aaaah... That requires reading...  Tongue  Wink

* Elessa smacks her palm to her forehead

and wouldn't ye know it? this just happens to be a forum for a text-based game!  oh heavens, ye are right.  reading, what a concept! Grin
Logged

Uuma ma ten rashwe, ta tuluva a lle

Play the latest beta version here on LoGD DragonPrime - Axebridge
XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #14 on: September 14, 2005, 11:15:16 PM »

Reading is by far the WORST spoiler in this game... And still many people don't manage to get those hints, even if you make them bright yellow (`^) between pale gray (`7)... Wink
« Last Edit: September 14, 2005, 11:15:51 PM by XChrisX » Logged

Running for more than three years now:
Pages: [1] 2   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Please take the time to read the FAQ and browse the DragonPedia

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
47 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search