Jump to content

Andy-H

Members
  • Posts

    2,000
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Andy-H

  1. $sql = "UPDATE users SET logo = '". mysql_real_escape_string($n) ."' WHERE id=". (int)$id ." LIMIT 1"; Note the LIMIT 1, I assume that since you're searching by ID you're only expecting 1 result be returned. The LIMIT 1 stops searching once that result has been found. Also, mysql_ functions have been soft deprecated, see mysql_query, it is advisable to use PDO or MySQLi instead. ----- $n is not a very descriptive variable name, it is considered good practice to use descriptive variable names, this way, if you (or anybody else) come back to the code in future, you have a better chance of understanding what the code is trying to achieve.
  2. I went but haven't been on PHPFreaks in a long time, I went as a helper so got my ticket for free =D What talks did you go to?
  3. Hi, I recently attended the PHPNW conference in Manchester, which was great =] In the post-conference email, I received a voucher code for 50% off the ZCE exam voucher, and my employer offered to pay for it, result! =D Now that the voucher is paid for, I have been looking for relevant study material to prepare for the exam, but it is scarce. I was just wondering if anyone has done the ZCE, and any decent advice or reading material for preparation would be much appreciated. I have found a few practice tests and read the free 5.3 study guide from zend.com, which aside from making me realise I need to RTFM (well, a few sections) a few times, wasn't a great deal of help. Also, does anyone know the pass rate? Zend seem to actively avoid disclosing this, which makes no sense at all to me, but these things happen. Thanks for any help.
  4. Reference no. is nothing special, just another variant field, the only difference is that it's required, how about this: products - product_variants - variant_attributes - attributes id - id - variant_id - id ... - product_id - attribute_id - attribute - value Then I only need to add the required fields, eliminating the need for null fields, and I could run a #get filters SELECT id, attribute FROM attributes #get filter options SELECT DISTINCT value FROM variant_attributes WHERE attribute_id = $id #get filtered products SELECT p.* FROM products p INNER JOIN product_variants pv ON ( p.id = pv.product_id ) INNER JOIN variant_attributes va ON ( pv.id = va.variant_id ) WHERE va.attribute_id = $filter_key AND va.value = $filter_value
  5. Products are plastic containers, capacity refers to the capacity of the container, i.e. 1000ml, I am only focusing on the product-product variant schema as I am happy with the rest of the database design. So we have a main table, holding product-specific data, variants are the same product, i.e. same shape bottle, make/manufacturer etc. but can vary in capacity etc. each variant must have a reference number, but the rest of the data can be NULL. I also need the ability to search products by variant values, i.e. where capacity = 1000 (ml) and would prefer if I could retrieve the filter options dynamically, hence my leaning towards EAV. I read the stack overflow post but none of the options screamed eureka at me.
  6. http://i45.tinypic.com/30mq1lh.png Sorry, it's this new forum software, I did actually attach it :/
  7. Hi, I have attached a partial of my database design schema, I can't think of a way to re-design it flexibly without using EAV, any suggestions?
  8. function isset_or($isset, $or) { return isset($isset) ? $isset : $or; } Save to lib/php, simples =P
  9. I have this query, and I'm using explain extended and optimising with an "INDEX" type index on the orders table, I've got it down from 6.5 to 3.5 seconds with an index on id, orderid, saleby. SELECT o.orderid, o.ordername AS ref, ROUND(SUM(totalcost), 2) AS total, IF( LENGTH(c.company), c.company, CONCAT(c.title, ' ', c.FirstName, ' ', c.Surname) ) AS customer, o.ordertime FROM orders o USE INDEX ( last_5_orders ) INNER JOIN ( orderinfo oi ) USING ( orderid ) INNER JOIN ( customer c ) ON ( c.custid = o.customerid ) WHERE o.saleby = 1 GROUP BY o.orderid ORDER BY o.id DESC LIMIT 5 Could anyone point me in the right direction? Or a decent tutorial on how to optimise using explain extended. Cheers, Andy
  10. I don't really use FULLTEXT indexes, what are the advantages to it? I don't need referential integrity and I was kind of hoping to use PDO transactions. What about the InnoDB row level locking though? TO me that implies that when using MyIsam a table is not "full duplex" so to speak, so I can't read from a table during a right, I need my reads to be high priority whilst the writes are high volume. Would this still be a case for MyIsam?
  11. Hi, was just wondering if anyone could help me with storage engines, I have done some researching but it seems that this is a grey-area that isn't looking likely for being resolved any time soon. I have a database, with one particular table that will get 35k~ inserts/ day and be read from around 5-10k times / day, I was wondering which storage engine to use. From what I read it was starting to look like InnoDB was a clear winner, due to row-level-locking, but then I read that MyISAM is faster? I then asked for advice in #mysql on freenode and was told "Use InnoDB, it's ACID compliant and supports x, y and z', but when I asked for the reasoning behind this all was quiet, and I didn't want to blindly follow advice without understanding why I was following it, or if I was even right in doing so. P.S. It doesn't have to be MySQL, but that's what I know, so why introduce more complexity? Also, what are peoples thoughts on persistent connections, as I currently spawn/close a connection on a per-request basis. CHeers.
  12. OK, cheers. So just use whichever looks 'prettier' lol
  13. Just as a little-more in-depth explanation: I am unsure as to which way to go here as a journey is an entity in itself (a collection of latlng locations, grouped with speed, bearing etc.) but it belongs to a device, i.e. can not exist without being created by (and linking to) a device, I am only just learning about REST and don't know what to do in this situation to conform to it. I'm not bothered about strictly conforming to REST, i.e. supplying cache information with date etc. but would like to follow the url structure, idea of GET/PUT/POST/DELETE and HTTP response code error reporting.
  14. Hi, I want to write a RESTful API to interface with our tracking units database, I was just wondering, which of the following would be closest to RESTful design: To request a journey: /devices/identifier/journeys/start_date/end_date /devices/identifier/journeys/journeyID or /journeys/device_identifier/start_date/end_date /journeys/journeyID Thanks for any help.
  15. Managed it: ~^/shops/?(?P<lat>([-+]?[0-9]*\.?[0-9]+))?/?(?P<lng>([-+]?[0-9]*\.?[0-9]+))?/?(?P<radius>([0-9]+?))?$~u
  16. I have the following regular expression, was just wondering if anyone knew of a way I could make the last forward-slash and parameter (radius) optional, thanks for any help ~^/shops/(?P<lat>([-+]?[0-9]*\.?[0-9]+))/(?P<lng>([-+]?[0-9]*\.?[0-9]+))/(?P<radius>([0-9]?))$~u
  17. No there is no 'infinite' rvalue in PHP. function unsigned($int) { return ($int < 0) ? (~(int)$int) + 1 : (int)$int; } $i = 25; $n = -55; $i = unsigned($n) + 1; if ( $i < unsigned($n) ) { // this effectively does what you ask for, but what's the point? }
  18. Personally, I wouldn't do it that way, I'd do this: // do whatever you need to do header('location: Admin.php?backup=true'); exit; //Admin.php <?php if ( isset($_GET['backup']) ) { // do whatever? $backupMessage = 'FreeExam database backed up successfully'; } ?> // html <?php echo isset($backupMessage) ? $backupMessage : ''; ?>
  19. And yet you only have 204 posts You could try something like this: header("Refresh: 5; Admin.php"); echo "<script language='javascript'>alert('FreeExam database backed up successfully');</script>"; Post count is not directly proportional to skill, knowledge or number of times a user has been helped, or has helped others. As you've proven time and time again
  20. I've also been pondering this one for a while, why not wait for the 5.4 though? Also, if anyone knows of any decent, free practice tests or learning material, please share!
  21. Perhaps syntax highlighting in the editor that was used to write the code messes up when it see's <?php (even when quoted as a string?) would be a crappy oversight on the SDK developers part but I can't really think of anything else?
  22. That's not possible, if you use GET variables they will be displayed in the URL, you could make it neater using mod_rewrite: .htaccess <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+[^/])$ index.php?page=$1 [NC,L,QSA] </IfModule> Untested.
  23. Please see my edit, the patten you quoted will match & followed by 3 or more alpha-numeric / hyphen characters followed by ANYTHING but a hyphen i.e. &75gg45g---54g-g54g%
  24. /^&[a-zA-Z0-9-]{3,}[^-]$/ //Edit If you meant ends with an alpha-numeric character, this rule matches '&' followed by AT LEAST 2 alphanumeric and hyphen characters, followed by one or more alphanumeric character /^&[a-zA-Z0-9-]{2,}[a-zA-Z0-9]+$/
×
×
  • 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.