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
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 10-09-2007, 12:57 PM   #21 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 700
Thanks: 2
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, 01:26 PM   #22 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 651
Thanks: 82
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, 01:10 PM   #23 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 651
Thanks: 82
Tanax is on a distinguished road
Default

?????
Bump :P
Tanax is offline  
Reply With Quote
Old 10-11-2007, 01:24 PM   #24 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 436
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, 01:31 PM   #25 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 651
Thanks: 82
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, 01:34 PM   #26 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 436
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, 01:35 PM   #27 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 651
Thanks: 82
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, 04:07 PM   #28 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 651
Thanks: 82
Tanax is on a distinguished road
Default

Works like a charm! :)

Thanks salathe
Tanax is offline  
Reply With Quote
Old 10-11-2007, 04:41 PM   #29 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 700
Thanks: 2
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, 05:50 PM   #30 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 651
Thanks: 82
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
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 12:44 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0