Jump to content

cpd

Members
  • Posts

    883
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by cpd

  1. Here your saying: (any lower case a-z) / (any lower case a-z or - (hyphen)) map into domain.com/firstValue/secondValue.php Its not quite correct. Not sure what level of programming you are with PHP but you may want to look into routers, as scootstah has pointed out, if your going to get into pretty URIs as your current thinking would redirect to a single page; it is not dynamic. If you were looking to do it for that specific page you want something like: RewriteRule ^products/category/([a-zA-Z-]+)$ location/of/file/roomproductscategorised.php?room=$1 Allowing you to write http://www.domain.com/products/category/bedroom/. In reality though, this isn't particularly useful as its a combination of the server-side language combined with htaccess that gives a good system which leads us back to the whole routers and what not.
  2. I've never considered using a URI router before. I would probably benefit massively creating a router and instead of having everything hard-coded for a controller/action format, just instantiate the controller and execute the action based on the command in the URI? That offers a far more dynamic approach to how the URIs can be constructed as I don't HAVE to follow the controller/action set-up, what do you think scootstah? That's the fundamental purpose of the router I guess, to provide dynamics.
  3. I don't think that achieves what he's trying to do. It'll just come back with count's. I think you need to look at pulling the data with the result set ordered by the DoB. Then cycle through your result set creating a new array which has a structure of. array( '1990' => array( 0 => array( 'First name', 'Last name' ), 1 => array(...), '1991' => array(...) ) When selecting you return entire rows with true values or NULL dependant on how the whole table and select statement is set-up. You can't get it to chuck out 1990 and then all the corresponding rows.
  4. I'm yet to find a limit and have built some extremely large sites using that method. I'm still struggling to grasp why that method isn't good for large sites, and yes it has been suggested before to me but never explained.
  5. If tep_href_link returns a completed anchor tag then it won't be possible to make the entire text a hyper-link using that method. If however, it just returns a URI than you should use the following $info_box_contents[] = array('text' => '<a href="'.tep_href_link(FILENAME_SHOPPING_CART).'">There are '.$cart->count_contents().' items in your cart</a>'); If "text" is your only array key you may also want to consider removing the array entirely and just having: $info_box_contents[] = '<a href="'.tep_href_link(FILENAME_SHOPPING_CART).'">There are '.$cart->count_contents().' items in your cart</a>';
  6. Thats entirely dependent on how you've defined your regex in htaccess. In your case it appears as though you can have domain.com/this-is-my-url/ but I'm not convinced you can have anything after that. Moreover, it takes the this-is-my-url and expects it to be a PHP page. Your better off redirecting everything to a handler page and either appending a query string or giving the re-written URL some structure. E.g. I often use RewriteRule ^([a-zA-Z0-9-]+)?/?([a-zA-Z0-9-]+)?/?(.*)$ site.php?controller=$1&action=$2&queryString=$3 Where $1 corresponds to the first set of brackets and so on.
  7. You've miss-understood. The point I was making is anybody can write a class which implements a method called "_export". class Foo { private $bar = "Something"; public function _export(){ echo $this->bar; } } By posting $this->_export() and asking where its from will get you zero answers.
  8. I've recently finished a class that uses the method _export myself... ^^ as above ^^
  9. There is no full proof method I know of. You can guess the region using the IP address and decline access based on that, but as most people are aware this isn't full proof. This could all change very easily however, with IPv6 which starts rolling out toward the end of 2012.
  10. Really? I was under the impression its only found its feet within the last 5 years or so and the whole "middle-tier" thing will now begin getting pushed out as security at the SQL Server level is getting increasingly better and the logic can now be carried out at the SQL Server level?
  11. Yes I understand and everything I've said already leads you to what you want to do. You have two methods $stmt = "SELECT `email` FROM `table` WHERE `email` = '{$email}'"l $res = mysql_qyery($stmt); if(mysql_num_rows($res) > 0){ // Email exists } else { // Email doesn't exist } Or $stmt = "SELET COUNT(`email`) AS `count` FROM `table` WHERE `email` = '{$email}'"; $res = mysql_query($stmt); $array = mysql_fetch_assoc($res); if($array['count'] == 0){ // Email doesn't exist } else { // Email exists } If you use a COUNT function you will ALWAYS get a result set (provided the SQL statement is valid) therefore, num_rows will not determine if an email exists in the database or not.
  12. If you want to test if an email address is in the database, remove the count function. Also why does fetch_assoc return a number? Surely that should return a parsed row?
  13. Its because your using a COUNT function. You will always get a result set because if no rows are found matching your query, it will return a count of 0. This will in turn cause num_rows to return 1 I also noted you have a >= 0 in your if statement. So you want it to error if there are no rows as well as if there are rows? That doesn't really make sense.
  14. foreach($items as $item) var_dump($item);
  15. Perhaps I wasn't specific enough. What this chap is trying to do in SQL is still in its infancy. Its very similar to T-SQL which is also in its infancy, hence why I drew that conclusion. MySQL does not use T-SQL however, it mimics a lot of what SQL Server does E.g. Try statements can be replicated with handlers in MySQL, therefore making it similar and correct me if I'm wrong, but is this chap not trying to use handlers (may be wrong as I've never used them)? Stored procedures are gradually being used more and more to write logical actions and this is often done in an SQL Server with T-SQL. Once again, if you look very closely, you will note he's tried to take his logic and put it in the MySQL Server with shed loads of if statements and what not.... see my point? Try thinking outside the box before loosing respect for someone.
  16. You don't need apostrophes for integers; strings only.
  17. Exceptions are extremely handy when you want to handle errors but continue executing your code. They can be extremely useful between different objects where one object can catch the error thrown by another and handle it appropriately. This allows continued execution of the code rather then a straight up error message from PHP displaying on the page. For example, you may have an FileObject which can read and write to files. The FileObject is instantiated and a method open($file) is called. This method checks to see if the files exists before trying to open it and if $file does not exist, it throws an exception which can be caught and handled appropriately. You could pass the thrown error to a MessageHandlingObject which in turn prints any errors that have occurred during execution. When you should and shouldn't use exceptions is somewhat subjective. Its down to the programmer however, you shouldn't be throwing exceptions if you can't then trace them back to where they originated as this can then cause problems for developers who follow in your footsteps. Exceptions are brilliant if you want to continue executing your code even if errors occur, this is why the phrase "try" is used as you try to do something and if it doesn't work, handle it appropriately and carry on. In your situation I would probably be doing something like. class MySQLAdaptor { public function query($sql){ $res = mysql_query($sql); if(!$res){ throw new Exception(mysql_error); } } } try { $sql = new MySQLAdaptor; $sql->query("SQL CODE"); } catch(Exception $e){ var_dump($e); } Although, many people would argue an error when executing a query is fatal and could cause harsh problems with your entire application therefore, exceptions shouldn't be used. I believe its largely down to what query your executing. If its not a vital query you could throw the exception and handle it, if its very important you could just let the code error.
  18. The obvious thing to say is your trying to implement features of PHP (and other programming languages) into SQL. SQL is a language in its infancy and as such does not support anywhere near what other languages do; it also never will as its purpose is different to that of standard programming languages. Taking the code from a mysql_query execution and placing it in a stored procedure does not necessarily make it more efficient or faster, in-fact I find it hard to believe it will do either. Techniques such as indexing are what will make your queries more efficient.
  19. Yeah I was having a bad day. When I reviewed this the next day I realised what I'd been doing and I didn't want a sub query as I don't believe it would have been particularly efficient.
  20. My point is you need to confirm your "re-setting" the cookie with an expiry time in the past. The browser may have a bug but like I previously said, I doubt it.
  21. You should probably of put this in the PHP Freelancer forum.
  22. Cookies are destroyed by your browser, all setcookie does is sent a request to the browser to set the cookie - be it in the past or future. The browser then removes any expired cookies. Have you confirmed the setcookie(foo, bar, time-3600) is definitely being executed? I find it hard to believe your browser isn't functioning properly unless you've developed your own browser.
  23. I'm inclined to disagree. An MSSQL database - or any database for that matter - doesn't have to reside on the same server as the web server. SQL Server is a typical example where the database often resides elsewhere. Therefore, someone can gain access remotely should they get hold of the credentials. Consider setting up levels of access including permissions granted to specific schema's - should your database warrant them - tables and whatever else. If your deleting records consider setting up a processing system where by a cron, or similar, is set off to process a deletion list every night. This will stop anybody using the front-end UI from removing any records in the database should they find a loop-hole. Might be a little off topic but its still security related.
  24. I've got a list of sundries in a relational database and there are currently 2 for this particular booking. When using the SUM function it only returns a single sundry where as without the SUM it returns both rows. SELECT s.sundryID, s.name, s.cost, bs.quantity, (bs.quantity * s.cost) AS sundry_total, r.roomNo, SUM(bs.quantity * s.cost) AS total FROM bookings_sundries AS bs LEFT JOIN sundries AS s ON s.sundryID = bs.sundryID LEFT JOIN bookings_details AS bd ON bd.id = bs.bookingDetailsID LEFT JOIN rooms AS r ON r.roomID = bd.roomID WHERE b.bookingID = 1 I'm baffled as to why. The total column appears no problem but like I said it only shows a single row as opposed to both the rows. I would have expected both rows to be shown with the `total` appearing at the end of each row. Bare in mind this is all happening in phpMyAdmin.
  25. Throw it all in the bin and write your own stuff. Cba with fiddly things like that, you spend more time figuring out how to use the bloody thing. An autoload function can be defined in minutes but whatevs.
×
×
  • 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.