View Single Post
  #2  
Old 12-14-2013, 11:46 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
If you're going to use SQL, you should leverage it else where.

Are you going to have a character slot system? If so you should establish a 'characters' table. I.e.

Characters

ID
Account

Then your other tables you should use the Character ID as the reference. I.e. For Quests:

Quests

ID - Autoincrementing integer
ScriptID - String - quest_id
Name
Description

QuestProgress

ID - Autoincrementing integer
Quest ID - Integer - Quest's ID
Character ID - Integer - Character's ID
Completed (Boolean)

Using this structure you can perform queries like...

PHP Code:
// Returns all quests player is currently on and has completed
public function getQuestData(pl) {
  
temp.statement format("SELECT Quests.name AS quest_name, Quests.description AS quest_description, QuestProgress.completed AS quest_completed
                             FROM Quests, QuestProgress
                            WHERE Quests.ID = QuestProgress.QuestID
                              AND QuestProgress.CharacterID = %s"
formatstring2(pl.clientr.characterid));
                              
  
temp.response requestsql(temp.statementtrue);
  if (
temp.response.rows.size() > 0) {
    
temp.data = {};
    for (
temp.rowtemp.response.rows) {
      
temp.data.add({
        
temp.row.quest_name,
        
temp.row.quest_description,
        
temp.row.quest_completed
      
});
    }
    return 
temp.data;
  } else {
    return 
"";
  }
}

public function 
getQuestsCompleted(pl) {
  
temp.statement format("SELECT COUNT(Quests.ID) AS quests_completed FROM QuestProgress WHERE QuestProgress.CharacterID = %s AND quest_completed = 1"formatstring2(pl.clientr.characterid));
  
temp.response requestsql(temp.statementtrue);
  return (
temp.response.rows[0].quests_completed);

__________________
Quote:

Last edited by fowlplay4; 12-14-2013 at 11:58 PM..
Reply With Quote