TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-09-2007, 11:57 AM   #21 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Create a vocations table with columns such as id, name, description which you can add rows for each of the available vocations. You can then search the players table for players by vocation name by JOINing the vocations table.

Code:
-- Example query to fetch players who are 'knights'
SELECT p.* 
FROM players p
LEFT JOIN vocation v ON v.id = p.vocation
WHERE v.name = 'knight'
Salathe is offline  
Reply With Quote
Old 10-09-2007, 12:26 PM   #22 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

o.OOO

So it my case it would look like this:
Code:
SELECT name FROM players LEFT JOIN vocation ON vid = vocation WHERE vname = $search
??

Code:
CREATE TABLE `players` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`group_id` INT NOT NULL DEFAULT 1,
`account_id` INT NOT NULL DEFAULT 0,

`level` INT NOT NULL DEFAULT 1,
`vocation` INT NOT NULL DEFAULT 0,
`health` INT NOT NULL DEFAULT 150,
`healthmax` INT NOT NULL DEFAULT 150,
`experience` INT NOT NULL DEFAULT 0,

PRIMARY KEY (`id`),
KEY (`name`),

FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE CASCADE

)
ENGINE = InnoDB;

CREATE TABLE `vocation` (
`vid` INT NOT NULL,
`vname` VARCHAR (11),

PRIMARY KEY (`vid`),
KEY (`vname`)

) ENGINE = InnoDB;
Tanax is offline  
Reply With Quote
Old 10-11-2007, 12:10 PM   #23 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

?????
Bump :P
Tanax is offline  
Reply With Quote
Old 10-11-2007, 12:24 PM   #24 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Sorry, I thought Salathe had posted the solution. What your have replied with seems to be correct, have you tried it?
Karl is offline  
Reply With Quote
Old 10-11-2007, 12:31 PM   #25 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

No, cuz I don't wanna "try" a new sql operation without beeing sure it's working :P Don't wanna mess something up xD
Tanax is offline  
Reply With Quote
Old 10-11-2007, 12:34 PM   #26 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Your ok to play with SELECT commands as they only select data from the database, they do not modify it in any way.

EDIT: Just realised you were probably talking about your CREATE TABLE operations, not the SELECT. They seem fine, although you may want to create a relationship between the members and vocation table
Karl is offline  
Reply With Quote
Old 10-11-2007, 12:35 PM   #27 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Okey, I'll try it as soon as I get home! :)
Tanax is offline  
Reply With Quote
Old 10-11-2007, 03:07 PM   #28 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Works like a charm! :)

Thanks salathe
Tanax is offline  
Reply With Quote
Old 10-11-2007, 03:41 PM   #29 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

No problem at all. Like I tell everyone else, I'm here to help. And thanks to Karl for his part in this topic too :)
Salathe is offline  
Reply With Quote
Old 10-11-2007, 04:50 PM   #30 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yes ofc, thanks Karl! :D
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:52 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design