Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Alex the class you specified is wrong everytime you create a new instance of the class you'd get an error. new Image('bla'); new Image('bla');// cannot redefine CENTER already defined in .. Plus if you are writing for PHP4 (altough since 5.3.0 most hosts are now switching to PHP5) then keep it PHP4 or if you want to make use of all the OOP features PHP5 gives you then change your class for PHP5. Thus either: define('CENTER', 0, true); .. class Image { var $image, $ext, $file; function Image($im = null) { .. or: class Image { const CENTER = 0; .. public $image, $ext, $file;//altough you should consider private instead of public public function __construct($im = null) { ..
  2. I have updated it a bit: CREATE TABLE building ( id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(16), PRIMARY KEY (id) ); CREATE TABLE player ( id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(16), PRIMARY KEY (id) ); CREATE TABLE research ( id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(16), PRIMARY KEY (id) ); CREATE TABLE build_specification ( id INTEGER NOT NULL AUTO_INCREMENT, building_id INTEGER NOT NULL, # REFERENCES building (id) upgrade_level INTEGER, gold_cost INTEGER, lumber_cost INTEGER, stone_cost INTEGER, population_cost INTEGER, KEY fk_building_id (building_id), PRIMARY KEY (id) ); CREATE TABLE player_has_build ( player_id INTEGER NOT NULL, # REFERENCES player (id) build_specification_id INTEGER NOT NULL, # REFERENCES build_specification (id) PRIMARY KEY (player_id, build_specification_id) ); CREATE TABLE build_specification_dependency ( build_specification_id INTEGER NOT NULL, # REFERENCES build_specification (id) build_specification_id_dependency INTEGER NOT NULL, # REFERENCES build_specification (id) PRIMARY KEY (build_specification_id, build_specification_id_dependency) ); CREATE TABLE research_specification ( id INTEGER NOT NULL AUTO_INCREMENT, research_id INTEGER NOT NULL, # REFERENCES research (id) upgrade_level INTEGER, gold_cost INTEGER, lumber_cost INTEGER, stone_cost INTEGER, population_cost INTEGER, KEY fk_research_id (research_id), PRIMARY KEY (id) ); CREATE TABLE player_has_research ( player_id INTEGER NOT NULL, # REFERENCES player (id) research_specification_id INTEGER NOT NULL, # REFERENCES research_specification (id) PRIMARY KEY (player_id, research_specification_id) ); CREATE TABLE research_specification_dependency ( research_specification_id INTEGER NOT NULL, # REFERENCES research_specification (id) research_specification_id_dependency INTEGER NOT NULL, # REFERENCES research_specification (id) PRIMARY KEY (research_specification_id, research_specification_id_dependency) ); There are 3 main tables: Building, Player and Research, these hold the very specifics of each (name, image, ..). The tables _specification defines the cost on the players different resources. The tables _has_ defines which specifications the player already 'purchased' and the table _dependency defines which spefication holds a dependency on the presence of some other specification (that's why you need to know which specifications the player has already 'purchased'). Note: As you'll notice research and building are quite similar you may want to create one table for them and using a type to differentiate between them.
  3. Before you start building something you need to think things trough. An important part is your database design (atleast if your application is going to use one) if you already fail there then the development will mostly do to as your queries will become or to complex to maintain or to redundant. Unfortunatly their aren't any tutorials out there detailing how you go from concept to realisation and if their are then they most likely are written for those already familiar with the terms ruling you out as you don't understand what they are talking about. I have done the database design for you: # the buildings table holds all buildings in your game (if you use 'races' then add a _races_id) CREATE TABLE buildings ( buildings_id INTEGER NOT NULL AUTO_INCREMENT, buildings_name VARCHAR(32), PRIMARY KEY (buildings_id) ); INSERT INTO buildings VALUES (1, 'Town Hall'), (2, 'Cottage'); # the buildings_upgrades table holds specifications about the upgrade cost of a building # and other information like to which level the building is upgraded (it's up to your programming to make sure the user isn't able to upgrade # from level 1 to level 20 altough 'money' may be a problem to do so) CREATE TABLE buildings_upgrades ( buildings_upgrades_id INTEGER NOT NULL AUTO_INCREMENT, buildings_upgrades_buildings_id INTEGER, buildings_upgrades_to_level INTEGER, buildings_upgrades_gold_cost FLOAT, buildings_upgrades_lumber_cost FLOAT, buildings_upgrades_stone_cost FLOAT, .. KEY fk_buildings_upgrades_buildings_id (buildings_upgrades_buildings_id), PRIMARY KEY (buildings_upgrades_id) ); INSERT INTO buildings_upgrades VALUES # it costs 1000 gold, 1000 lumber and 1000 stone to create a level 1 town hall (1, 1, 1000, 1000, 1000, ..), # it costs 2000 gold, 500 lumber and 1500 stone to create a level 1 cottage (2, 2, 2000, 500, 1500, ..); # the buildings_upgrades_dependencies table is meant for if a upgrade relies on the present of other upgrades CREATE TABLE buildings_upgrades_dependencies ( buildings_upgrades_dependencies_buildings_upgrades_id INTEGER NOT NULL, # the upgrade building buildings_upgrades_dependencies_buildings_upgrades_depency_id INTEGER NOT NULL, # the upgrade building on which buildings_upgrades_id relies PRIMARY KEY (.._buildings_upgrades_id, .._buildings_upgrades_dependency_id) ); INSERT INTO buildings_upgrades_dependencies VALUES # to build a town hall level 1 you need a level 1 cottage (1, 1); # the players_buildings table holds all buildings and it's current level the player has purchased CREATE TABLE players_buildings ( players_buildings_players_id INTEGER NOT NULL, players_buildings_buildings_id INTEGER NOT NULL, players_buildings_level INTEGER, PRIMARY KEY (players_buildings_players_id, players_buildings_buildings_id) ); INSERT INTO players_buildings VALUES # player #1 has a cottage and a town hall both at level 1 (1, 2, 1), (1, 1, 1); # if the user upgrades you'd perform the following query: #UPDATE players_buildings SET players_buildings_level = $to_level WHERE players_buildings_players_id = $id AND players_buildings_buildings_id = $buildings_id
  4. add a field to your users table 'avatar' (for example) that will hold the link to your image. If someone now uploads it's image then the last one uploaded with be inserted into the database. It's up to you to delete the old image using the previous value of avatar if present.
  5. They use something like preg_match Once they have all matches they look if it is one of the possible resources (function, ..). If it is they replace it with the output of the resource. $matches = array(); if (preg_match('/{([A-Z-_]+)}/i', $str, $matches)) { foreach ($matches as $match) { $functionName = strtolower(trim($match, '{}')); if (function_exists($functionName)) { $output = call_user_func($functionName); $str = str_replace($match, $output, $str); } } }
  6. $maxWidth = 150; $maxHeight = 150; list($width, $height) = getimagesize('path/to/image'); $ratio = 1; if ($width > $maxWidth) { $ratio = $maxWidth / $width; } else if ($height > $maxHeight) { $ratio = $maxHeight / $height; } $newWidth = $width * $ratio; $newHeight = $height * $ratio;
  7. The dispatching process is being performed by the FrontController pattern internally it will use a router of some kind to map a request to a physical location (a file on your hard drive). So if you would get a request like: /users/me It could translate to: UsersController::meAction() The translation would be made possible by your router and a few function calls that translate users to UsersController (same for me). Afterwards a dispatcher will use UsersController and meAction and will try to execute it.
  8. Ah k I get it. But that 1,3,5 shouldn't be in your table as now you can't work with it to gather the skills the user has use it like: CREATE TABLE users_skills ( skills_sellers_id INTEGER NOT NULL, skills_id INTEGER NOT NULL, PRIMARY KEY (skills_sellers_id, skills_id) ); INSERT INTO users_skills VALUES (1, 1), (1, 3), (1, 5); I created 3 rows and they all have 1 for skills_sellers_id (your user's id) and that matches up with 1, 3 and 5 (his skills) If you now would select all skills (ids) for that user: SELECT skills_id FROM users_skills WHERE skills_sellers_id = 1 Returns 1, 3 and 5 Now to get the name for that skill id: SELECT * FROM skills LEFT JOIN users_skills ON skills.id = users_skills.skills_id WHERE skills_sellers_id = 1 Now to PHP: $id = /*retrieve user id from session or wherever it is stored*/; $query = "SELECT skills.skill, skills_sellers_id, skills_id FROM skills LEFT JOIN users_skills ON skills.id = users_skills.skills_id WHERE skills_sellers_id = $id";// This will give us all skills $result = mysql_query($query); print '<select name="skills">'; while ($row = mysql_fetch_assoc($result)) { echo '<option value="', $row['skills_id'], '"', ((null != $row['skills_sellers_id']) ? ' selected="selected"' : ''), '>', $row['skill'], '</option>'; } print '</select>'; I have pulled a little trick here I used LEFT JOIN which will get all rows from skills even if their is no record for in users_skills (whereby skills_sellers_id = null) which will cause to list all skills (even those the player doesn't have if you don't want that, remove LEFT + 1) and will 'highlight' (selected="selected") all skills the player has. Take a look in phpMyAdmin and provide this query: SELECT skills.skill, skills_sellers_id, skills_id FROM skills LEFT JOIN users_skills ON skills.id = users_skills.skills_id WHERE skills_sellers_id = 1 (1): echo '<option value="', $row['skills_id'], '" selected="selected">', $row['skill'], '</option>';
  9. It contains 'children' if you would print $categories you would get: Array ( $parentId => Array ( 'children' => Array ( 0 => Array ( 'id' => $id, 'name' => $name), 1 => Array ( 'id' => $id, 'name' => $name), .. ) ) ) I used $parentId, $id and $name these would translate to what they hold at that time ofcourse.
  10. Thx Daniel for your reply.
  11. Hi, How do you generally bootstrap your application or which other methods do you know besides: #1: Switch (Not really the best approach) switch ($page) { case 'home': include('home.php'); break; .. } #2: Using routing (most used) $defaultRoute = array('default', 'route', 'parts'); $errorRoute = array('error', 'route', 'parts'); $route = uri2route(); dispatch($route); #3: 'RESTful' based This is something I have been playing with. A browser is just another device like CLI to access your 'website' (or the data at that resource identifier) through the Accept header can the application identify what it should return. What are your thoughts, suggestions?
  12. Plugins are based upon the observer pattern, when a plugin is loaded it registers itself to 'hook' into a section of your application: $pluginRegistry->register(new Plugin('sectionHook')); Afterwards when you reach a section of your application that allows plugins: $someClass->getPluginsFor('sectionHook')->execute($dataObject); Every plugin now gets the $dataObject passed and has the ability to modify it, for example user entered text: the 1st plugin modifies all e-mail addresses into clickable 'mailto:' addresses, the 2nd plugin modifies all web addresses to clickable web addresses, .. A module is part of a modular application (or a module is a mini-application inside of your application, some use the term widget instead of module) A module contains everything it uses (images, scripts, styles, libraries, ..) unless it's already present in the main application. Using this approach makes it possible to drag-and-drop your module into another application (atleast if it contains the libraries your module requires).
  13. Change it back to: $sql_skill = "SELECT * FROM skills ORDER BY skill ASC"; $result_skill = mysql_query($sql_skill); while ($rs_skill = mysql_fetch_array($result_skill)) { print "<option value=\"".$rs_skill["id"]."\"".(isset($_POST['skill']) && in_array($rs_skill['id'], $_POST['skill']) ? ' selected="selected"' : '').">".ucwords($rs_skill["skill"])."</option>"; } What does the table skill_sellers then contain?
  14. class Image { var $image, $ext, $file; public function __construct($im=NULL) define('CENTER', 0, true); define('CENTER_LEFT', 1, true); define('CENTER_RIGHT', 2, true); define('TOP_CENTER', 3, true); define('TOP_LEFT', 4, true); define('TOP_RIGHT', 5, true); define('BOTTOM_CENTER', 6, true); define('BOTTOM_LEFT', 7, true); define('BOTTOM_RIGHT', 8, true); Alex couldn't decide if you would write for PHP 4 or 5? class Image { const CENTER = 0; .. private $image; private $ext; private $file; public function __construct($im = null) }
  15. I would go for the Yahoo Media Player
  16. function get_table_content($db, $table, $handler) { $schema_insert = ''; $result = mysql_db_query($db, "SELECT * FROM $table") or mysql_die(); $i = 0; while($row = mysql_fetch_row($result)) { // set_time_limit(60); // HaRa $table_list = "("; for($j=0; $j<mysql_num_fields($result);$j++) $table_list .= mysql_field_name($result,$j).", "; $table_list = substr($table_list,0,-2); $table_list .= ")"; if(isset($GLOBALS["showcolumns"])) $schema_insert .= "INSERT INTO $table $table_list VALUES ("; else $schema_insert .= "INSERT INTO $table VALUES ("; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= " NULL,"; elseif($row[$j] != "") $schema_insert .= " '".addslashes($row[$j])."',"; else $schema_insert .= " '',"; } $schema_insert = ereg_replace(",$", "", $schema_insert); $schema_insert .= ");\n"; $handler(trim($schema_insert)); $i++; } return $schema_insert; }
  17. function get_table_content($db, $table, $handler) { $result = mysql_db_query($db, "SELECT * FROM $table") or mysql_die(); $i = 0; while($row = mysql_fetch_row($result)) { // set_time_limit(60); // HaRa $table_list = "("; for($j=0; $j<mysql_num_fields($result);$j++) $table_list .= mysql_field_name($result,$j).", "; $table_list = substr($table_list,0,-2); $table_list .= ")"; if(isset($GLOBALS["showcolumns"])) $schema_insert = "INSERT INTO $table $table_list VALUES ("; else $schema_insert = "INSERT INTO $table VALUES ("; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= " NULL,"; elseif($row[$j] != "") $schema_insert .= " '".addslashes($row[$j])."',"; else $schema_insert .= " '',"; } $schema_insert = ereg_replace(",$", "", $schema_insert); $schema_insert .= ")"; $handler(trim($schema_insert)); $i++; } return $schema_insert; }
  18. SELECT heading, replies, type, mythreads$username.casenum mythreads_casenum, postnum.casenum postnum_casenum, mythreads$username.lastpost mythreads_lastpost, postnum.lastpost postnum_lastpost FROM postnum JOIN mythreads$username USING casenum
  19. mark it as solved please.
  20. SELECT * FROM postnum JOIN mythreads$username USING casenum I am still unsure of what you actually want to achieve.
  21. $data=$_FILES[logfile][name]; (more appropriate syntax is: $data=$_FILES['file']['name']; and not logfile but file) should be: $data=$target;
  22. $search = 'c6'; $str = '111c6,vvvc6222,c6c6,444c6'; $parts = explode(',', $str); $sizeof = sizeof($parts); for ($i = $sizeof - 1; $i >= 0; --$i) { if (false !== strpos($str, $parts[$i])) { print $parts[$i]; break; } }
  23. In SQL please not CSV
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.