Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. It's not only JS, it's also PHP
  2. Try: $val_new = implode ("','", array_map('cleanQuotes', $arr)); I didn't notice you already included ' in the INSERT query or use: $query = "INSERT INTO parse_original (player1,player2) VALUES ($val_new)";
  3. $val_new = "'" . implode ("','", array_map('cleanQuotes', $arr)) . "'";
  4. You are passing in your data incorrect, it should be: $data = mysql_real_escape_string($data); $query = "INSERT ... (..., '$data', ..)"; instead of: $data = mysql_real_escape_string("'$data'"); $query = "INSERT ... (..., $data, ..)";
  5. list($first_quad, $second_quad, $third_quad, $fourth_quad) = explode('.', $ip_address);
  6. No, it's the other way around. Yes, it's a uniform approach to the num_rows/affected_rows problem. Return $this is used for method chaining, like so: $object->method()->method()->method()->method()->method() The execute() method doesn't do much and we want to abstract away as much as possible without breaking the client code. For example: foreach ($db->execute('SELECT * FROM table')->fetchAll() as $row) { print_r($row); } Of course this wouldn't work in my last posted code and you would need my previous code, where fetchAll() made use of fetchRow() or the code was changed to: $rows = $this->result->fetch_all($mode); return !empty($rows) ? $rows : array(); This would not break the client code as in the case where fetch_all() would return nothing an array would be returned.
  7. I thought of having read that somewhere that MySQL was primarily optimized for SELECT queries, but now I am doubting if it was MySQL or PostGreSQL that they mentioned... I read so many articles and sometimes forget to verify the source while fragments of it linger in my mind to create havoc and destruction every now and then Luckily we have Daniel and Mchl to rectify any wrongs. Edit: I can't find the article anymore so it's most likely to be false.
  8. Yes. Although before executing you may want to try this on a test database.
  9. It would still echo Jack. A socket that times out doesn't terminate your script instead (if maximum execution limit hasn't yet been reached) it executes the rest of your code.
  10. session_set_cookie_params(86400);//1 day session_start(); if (!array_key_exists('list', $_SESSION)) $_SESSION['list'] = array(); $requiredFields = array(); if (array_key_exists($requiredFields, $_POST)) { .. } session_set_cookie_params() needs to be called before session_start() as the session cookie may expire and we want to be sure each created session cookie will have a lifespan of 1 day.
  11. Use CRON to set when my script should execute. You will be able to find it in your CPanel. Test it first though like I already mentioned in the PM.
  12. When you upload an image you should also store it's content-type.
  13. SELECT .. FROM group RIGHT JOIN parts USING (grid) RIGHT JOIN features USING (grid) WHERE group.grid IS NULL
  14. On each of these occurrences you return the Database object. return $this->execute("DELETE FROM ".$table." WHERE ".$where); What would be a logical step for anyone using your database after executing a INSERT/UPDATE/DELETE query? That's right. To check if anything was INSERTED/UPDATED/DELETED and how would they do that? Knowing the execute() function returns a reference to itself. Also correct, you take a look at the plethora of functions the object provides, in this case numRows() would make sense. However if you call it, it returns "Calling an method on a non-object ..". Don't just copy-paste code and remove as you see fit, as the code may have value. Learn to understand the code before you recklessly remove it, learn to understand the implications that it may have in doing so (like the before mentioned "Calling a method on a non-object"). I can't teach you, if you aren't willing to learn.
  15. while ($row = mysql_fetch_assoc($result)) { echo '<div class="picture"><img src="photo.php?id=', $row['id'], '" title="', $row['title'],'" alt="', $row['title'],'"></div>'; }
  16. It has been a while since I used Zend framework I added a comment to my code that said you should check out what the error_handler object returned.
  17. You can use sessions/cookies but: 1) if you use session's and forget to set cookie lifetime the user loses his list upon closing his browser 2) if the user has set (or if in a corporate network the policy is set) to remove all cookies upon browser closing then again he will lose his list. Nothing else but a database (in any form: flat file, dbms) can certify data persistence.
  18. $queue = new SplQueue(); $dom = new DomDocument(); if ($dom->loadHtmlFile('http://path/to/html/file')) { foreach ($dom->getElementsByTagName('a') as $a) { if ($a->hasAttributes() && $node = $a->attributes->getNamedItem('href')) { $queue->enqueue($node->nodeValue); } } } foreach ($queue as $uri) { print $uri; }
  19. In my version I accounted for the boolean that query returns when you execute something else then a SELECT query and I also accounted for a uniform approach to affected_rows and num_rows, in either case you would call getAffectedRows() and get the correct number of rows selected, inserted, updated, or deleted. $db->execute('INSERT INTO table () VALUES ()')->numRows(); Would result in an error along the lines of "Calling method on a non-object ..." as where: $db->execute('INSERT INTO table () VALUES ()')->getAffectedRows(); Wouldn't.
  20. I wanted to show the worst-case scenario. And I indeed did not include indexes and stuff which would account for another 20%? I just wanted to point out that his current calculation was incorrect. Of course mine wasn't either correct as you pointed out but closer to the truth.
  21. 1) Is it possible to run a query that tells me which columns in a table are empty? (i.e. entries for, say, Mon, Wed, Thur, Fri are empty) Yes take a look at the CASE-statement for MySQL 2) Should I create a table for each user that tracks this on a weekly or bi-weekly basis? No. 3) Or should I just run a query on the table that needs to be updated each time the user logs in? Yes.
  22. Yes, as each result is added to an array.
  23. if (isset($_POST['Submit'])){ Does not exist as you wrote: <input type="submit" value="submit"/> Add name="Submit" and it should work. I always want to point out that your functions are tightly coupled to your code and it will be quite hard to use them elsewhere. For example a registration form that uses some different name's then username and password wouldn't work. Or if you would ever use something different then mysql then this wouldn't work either due to mysql_real_escape_string.
  24. I ain't patronizing. I am just saying that I was calculating the same thing you did.
  25. A real programmer pursues perfection. Don't settle for something that just works, make it better, easier to maintain/extend. And remove any redundant code.
×
×
  • 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.