Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. In what format did you save the spreadsheet? http://devzone.zend.com/27/reading-and-writing-spreadsheets-with-php/ is a good tutorial on how to read data from an Excel file for example. Buy Beginning Google Maps Applications with PHP and Ajax as it will teach you everything you need to know to create your complete custom map in Google Maps.
  2. I've delved into the code. <sarcasm>Thank you for providing a link BTW.</sarcasm> $character = $armory->getCharacter($charname) if ($character->isValid()) { // character was found } else { // character was not found... redirect } Try that. http://sourceforge.net/p/wowarmoryapi/home/Home/ -- WoW Armory API docs.
  3. Can you post the entire script so others may use it/learn from your experience?
  4. It was late when I posted this. I now realize a far better option would be to not expose the API at all and let the API return a path to an image. Something like: $image_url = file_get_contents('http://my-api-website.com/adverts-api.php?host=the-host-website&session=' . $somesessionid); echo '<img src="', $image_url, '" alt=""/>';
  5. <img src="http://yourwebsite.com/adverts-api.php?key=123" alt=""/> Verify if the referrer(?) matches the 123 key.
  6. Your DB design is off. 1 race has * classes. 1 class has 1 race (at least I didn't find any shared classes). 1 class has * skill types 1 skill type has * classes There are skill types and sub skill types (eg Scion). 1 skill type has * skills. 1 skill type has 0..* sub skill types. 1 skill has 1 skill type. This should be closer to the design you wanted to create. CREATE TABLE races ( race_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, race_name VARCHAR(11) NOT NULL ); CREATE TABLE classes ( class_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, class_name VARCHAR(6) NOT NULL, race_id TINYINT UNSIGNED NOT NULL, KEY (race_id) ); CREATE TABLE class_has_skill_type ( class_id TINYINT UNSIGNED NOT NULL, skill_type_id TINYINT UNSIGNED NOT NULL, PRIMARY KEY (class_id, skill_type_id) ); CREATE TABLE skill_types ( skill_type_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, skill_type_name VARCHAR(7) NOT NULL, skill_type_parent_id TINYINT UNSIGNED NOT NULL, KEY (skill_type_parent_id) ); CREATE TABLE skills ( skill_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, skill_name VARCHAR(7) NOT NULL, class_id TINYINT UNSIGNED NOT NULL, skill_type_id TINYINT UNSIGNED NOT NULL, FOREIGN KEY (class_id, skill_type_id) REFERENCES class_has_skill_type (class_id, skill_type_id) ) ENGINE=INNODB;
  7. Either through: Browser.php Or get_browser Mind though that for get_browser to work your browscap should be up-to-date, the latest version can be found here: http://browsers.garykeith.com/downloads.asp
  8. No offense, but if you can't answer that question you should consider looking for another job. if ($status['latitude'] && $status['longitude']) { Will skip the users with no valid latitude & longitude although you probably should put this in your query. WHERE latitude > 0 && longitude > 0 Which negates the need for an if statement in your foreach.
  9. Optimize your images, the background loads slowly.
  10. The ReportModel (maybe a wrong choice of words on my part) would do all the queries and the Report (or ReportView) would do the actual rendering.
  11. 1. Abstract your database, even if you make it as simple as just a Database class it allows for more flexibility to allow your report to work with more than just MySQL [OR] 2. Better yet, create a new class that uses a Database and let the report query to that new class: public function getPopularTopics($limit) { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) {$this->error = "There was a problem with the database"; return false;} while ($row = mysql_fetch_assoc($res)) { $topics[] = $row['Category']; } return $topics; } So instead of having a function getPopularTopics in your Report you would put the function in ReportModel: $this->getPopularTopics(); Then becomes: $this->reportModel->getPopularTopics(); *TADA* all query related material is now outside your report class and the code becomes less cluttered. Keep identifying responsibilities and figure out who should carry that responsibility, use GRASP to guide you. If GRASP is going above your hat, then try to get familiar with the concept through CRC cards.
  12. Yes that was the idea but it's an early sketch since there isn't much to go on. Maybe Employer and Family should also be separate classes since either would generate a different report? The report should also be flexible in that it will look different for each company or family (Composite and Decorator come to mind). You would then fill the Report with all the necessary data and use Decorators to render the report. So that by feeding different decorators you would get different reports (themes). If you have experience with Zend_Form you get what I mean. A generate(RenderEngine $e) could be used to tell what rendering engine should be used, the rendering engine would then inject the decorators to create PDF, DOCX, or simple HTML documents. I'm just rambling here but you can see that there are a lot of opportunities here.
  13. Your class has too much knowledge of everything. Since you are keeping track of Employee information (lastLogin, loginCount, sex, ..) and want to calculate totals, you could add an Employee and EmployeeCollection class. class EmployeeCollection implements Iterator, Countable { public function add(Employee $e) {} public function getAt($offset) {} public function setAt(Employee $e, $at) {} public function removeAt($offset) {} } class Employee { private /*@EmployeeSex*/ $_sex = null; private /*@DateTime*/ $_lastLogin = null; private $_loginCount = 0; } class EmployeeSex { // who said programming isn't sexy? ;-) const MALE = 'm'; const FEMALE = 'f'; const UNKNOWN = 'yet to be determined'; private $_sex = self::UNKNOWN; public function __construct($sex) {/*$sex can't be UNKNOWN*/} public function isMale() {} public function isFemale() {} } class Report { private /*@EmployeeCollection*/ $_collection = null; } You would query the collection for the necessary information: - total number of activated employees - total number of activated family members - count of male users - ..
  14. That's why this forum exists in the first place ;-) To help/advice people when they are stuck on some code.
  15. The pages are really heavy and load slow. Optimize the images by using an online service like SmushIt!
  16. ignace

    Zend search?

    No. Searching is done by querying your database. Lucene is just some product you can use as a front-end with your database to speed up full-text searches.
  17. Clearly having one class that has validation code for nearly everything is not gonna be too efficient, I'm not saying it will slow down your system just that it's not efficient. It would be better to have one class for each specific validation like Zend Validate does. http://framework.zend.com/manual/en/zend.validate.set.html
  18. $query = "select zone from delivery where country = '{$_POST['country']}";
  19. You can use them on any function that doesn't return a value. It's not exclusive for setters.
  20. I see xyph already helped you, I'll add the below code if anyone ever comes across this topic. I had a play with it yesterday and tried to mimic SQL like functionality in PHP for CSV files. Please use SQL for any large CSV file. class CSVFileObject { private $_file; private $_skipFirst; public function __construct($csvFile, $delimiter = ',', $enclosure = '"', $escape = '\\', $skipFirst = false) { $this->_file = new SplFileObject($csvFile); $this->_file->setFlags(SplFileObject::READ_CSV); $this->_file->setCsvControl($delimiter, $enclosure, $escape); $this->_skipFirst = $skipFirst; } public function rewind() { $this->_file->rewind(); } public function readLine($line = null) { if ($line !== null) { $this->_file->seek($line); } if (!$this->_file->valid()) { return false; } if ($this->_file->key() === 0 && $this->_skipFirst) { $this->_file->next(); if (!$this->_file->valid()) { return false; } } $line = $this->_file->current(); $this->_file->next(); if (!is_array($line)) { return false; } return $line; } } interface Matcher { public function match($o); } class CSVComplexSearch { private $_csv; public function __construct(CSVFileObject $csv) { $this->_csv = $csv; } public function findWhereMatches(Matcher $matcher) { $result = new ArrayObject; while (($line = $this->_csv->readLine()) !== false) { if ($matcher->match($line)) { $result->append($line); } } return $result; } } class MyMatcher implements Matcher { private $_line; public function match($o) { $this->_line = $o; return ( $this->_whereFirstNameIs('foo') && $this->_whereLastNameIs('bar') ); } private function _whereFirstNameIs($str) { return $this->_line[0] === $str; } private function _whereLastNameIs($str) { return $this->_line[1] === $str; } } You use it like this: $search = new CSVComplexSearch(new CSVFileObject('users.csv')); var_dump($search->findWhereMatches(new MyMatcher));
  21. $sql = "SELECT * FROM users WHERE username = '{$email}' AND password = '{$password}'"; $result = mysql_query($sql) or exit("ERROR: " . mysql_error() . "<br>IN QUERY: " . $sql); Gives you a description of what's wrong with your query. It's advisable not to use or exit() in production environments.
  22. You can just do it in MySQL: SELECT floor( (to_days(now()) - to_days(birthday)) / 365.25 ); Create a user-defined function age() in MySQL and you can do this: SELECT age(birthday) AS user_age;
  23. I would look into Zend or Kohana as both support DB abstraction and provice ACL management. Finding a PayPal component for Zend (or Kohana) won't be hard either but as it's not part of the official Zend distro I would suggest writing your own or at least ask sufficient advise concerning the subject as this is your main source of income and should be near error-free. The project looks easy enough IMO with these components in place.
  24. Now you made me curious, link?
×
×
  • 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.