Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. Ronyban, you are going to resembled the "ban" part of your name and become banned if you persist with this line of questioning. It appears that you're asking a test question, and we don't appreciate that here. If you have a specific question, you need to formulate it better.
  2. Geez doddsey, what is your problem? Are you really that lazy, that you when you have the query handed to you on a silver platter, which is a lot more than many people would contribute, you don't want to take the minimal work required to take what was overly complex code, and reduce it to the much simpler code required to get what you originally asked for, or is the problem that you just don't understand the answer you were given? I don't think it's laziness, but from mjdamato's point of view, he not only gave you the answer that any competent php/mysql developer would give you, he even wrote the query for you, which you admitted was correct. Would it help to understand that in one result set, all the data you need is available and you simply need to fetch each row, checking to see if the p.parent_id changed. If it did, you have a new table, so you need to close off the old one, start a new one, and of course assign the value to your parent_id variable. If you have to throw away the code you have, other than the query and start from scratch.
  3. Sure, you can use the javascript setInterval function. Here's a sample that sets up a form element and updates it every 2 seconds. <br /> function init() {<br /> document.forms["form1"].counter.value=0;<br /> }<br /> <br /> function updateCounter(){<br /> document.forms["form1"].counter.value++;<br /> }<br /> <br /> window.onload=function(){<br /> init();<br /> setInterval(updateCounter, 2000);<br /> }<br /> </pre> <form name="form1"> Counter: </form> <br><b
  4. The svn repo has to be internet accessible. If so, then yes, you're basically just making the server an svn client, and using the command line svn tool to pull the updates from the svn repo.
  5. If your staging area is a sandbox, you can get only the files that have changed using svn up. The only negative to this is that the .svn directories are also checked out, but you can deny access to these in apache easily enough.
  6. yeah well the function is named mysql_query() not mysqql_query.
  7. And in case you were wondering why, the basic format for a mysql date needs to be YYYY-MM-DD. You were inadvertantly passing the '05/01/2010' which is not a valid mysql string constant for a date column. The code that converted it does in fact work properly but because you did not actually pass the variable you constructed, mysql took that as an invalid date, and defaulted it to the 1970 date, which for a timestamp is the first possible date you can store.
  8. Ok, I think I see your problem: $query = "UPDATE news SET news_date = '$news_date', subject='$subject', news_artical='$news_artical' WHERE news_id = '$news_id'"; Notice that the variable needs to be $news_date not $new_date which is what you had.
  9. No. Here's a little test program to run. Make sure you look up regex characters and look at the manual page enough so you understand why my test program works. $subject = '@ban baduser needs to be banned'; $regex = '/@ban\s(\w+)/i'; if (preg_match($regex, $subject, $match) > 0) { echo "The username to ban is $match[1]"; } If you have specific questions, feel free to ask.
  10. Well, I don't have enough code to understand why this would work or not work, but the obvious question here is: -How would the script know the value of $username? -Why would '@ban fred' ever == '@banfred' -The php concatenation operator is '.' not +! *IF* and that's a big if here, you somehow have a value for username, which again, I don't see you having without some regex someplace), then your comparison would need to be something like: $_POST['text'] == '@ban ' . $username Basically, you seem to be down the wrong track entirely. Ignace gave you some code that is more along the lines of something OOP, but if that's too complicated for you to understand right now, then you'd be much better off looking into the use of http://us3.php.net/preg_match. Using that will get you a pattern match for '@ban' and the word following it can then be grabbed and used as the username.
  11. Again, you're not going to get any help with this until you inform us what $_GET['new_date'] contains when the script is run. We are not mind readers. Put in an: echo $_GET['new_date'] ; Also --- what is the datatype of the news_date column in the database. Something tells me that it's a timestamp.
  12. I'm not sure how we would know when we don't know what $_GET['new_date'] contains. I'm also not sure why you would use strtotime when you don't care about the time element, and only want a php date variable.
  13. Wow Dude, you are still using a PPC based mac! We need to take up a collection to get you upgraded But you do make a good point that netbooks and older comps will have an issue with virtualization. Virtualbox runs really well on any intel based machine, although you do need to have enough ram that you can aportion some off to the vm.
  14. It may be a day late on this, but it's just sooo much better to use a virtual machine. Sun virtualbox works great on the Mac. Then you can have your lamp setup without having to install all these services into your workstation. Last but not least, when you deploy onto a lamp server, you know that things will probably work fine because you developed under the exact same platform you'll deploy to.
  15. There is no difference between this query and the one he already had. This has nothing to do with his problem. Pikachu2000 already identified the issue. I've had problems using the syntax he's using, so that is why I suggested changing the string to what I posted. I'm sorry to be harsh, but that's poor advice. I can only suggest that you really study PHP "interpolation". The only issue with interpolation is that you can not include array variables using single quotes around the key, but even this has a workaround. $r['day'] = 'monday'; echo "today is $r['day']"; // syntax error echo "today is $r[day]"; // works but requires constant lookup echo "today is {$r['day']}"; // works Speaking personally, it is both easier to read and easier to maintain interpolated strings in my opinion. Having to concatenate every single variable is a lot of work, and a major headache when you have to alter queries.
  16. There is no difference between this query and the one he already had. This has nothing to do with his problem. Pikachu2000 already identified the issue.
  17. the only resource which is shared on a vps is the bandwidth.. on a vps you get ram, and then you get what they call burstable ram.. ram is what your account has dedicated.. so you will never be disallowed that much ram.. burstable ram is how much ram you could be bumped up to if other people aren't using as much RAM and your applications require more.. but that is your absolute max... and there is no guarantee to ever be able to touch your burstable ram limit.. most vps also give you a certain cpu percentage which you're dedicated, not sure if they have it set up for burstable also.. the only thing that is shared is the incoming and outgoing bandwidth There are different VPS technologies. The one Russell is referring to is Virtuozzo. It has this short term "burstable" setting that can grab some memory from the server pool at times of extreme stress. One issues with Virtuozzo is that VPS's do not have any virtual memory, so when you use up all your allocated memory, things start to die. Because Virtuozzo maximizes the use of the available server resources, it's very popular with hosting companies. Xen is the basis for other companies and has more robust virtualization. You see Xen used on Amazon EC3 and with certain hosting companies. A Xen guest gets a certain amount of ram from the total amount available on the server at startup and will never get more or less than that. In either case you get a certain allocation of memory that you can depend on, and more importantly you have root on the server, and can manage it any way you see fit. When you want to change php settings, you can go in and edit the /etc/php.ini file and restart apache -- things that you can't do on a shared host.
  18. The framework that is the most like Ruby on Rails (and I must agree strongly that it is not a design pattern) is Symfony. The team that put symfony together did so largely as a way of emulating what they liked about RoR, only using various pieces of projects they found available in the PHP world. One part of RoR that is a design pattern is "Active Record" and often when people talk about what is good about RoR, they are talking about "code generation" using database introspection and RoR's implementation of "Active Record". Well, quite frankly, nearly every framework has some form of "Object relational manager" for working with the database. Symfony has these same features in terms of comes with integrated MVC, ORM and code generation to build the ORM mapping classes and generate CRUD. You can debate the strengths and weaknesses of the various PHP ORM's plenty. When RoR came out, Ruby didn't have ORM options, so "Active Record" was a big step forward. PHP has several ORM's to choose from. Java advocates will be happy to tell you that in terms of ORM's Java was way ahead of Ruby and PHP, and often the ORM's in these languages are ports or copies of a well known Java ORM's. There are actually a fair number of PHP ORM's right now, with the two best known being Propel and Doctrine. If you take a look at Symfony, while they started with Propel support, they quickly added support for Doctrine. This is a trend (decoupling the ORM from the rest of the framework) that even has been adopted by the Ruby on Rails people. I find myself being somewhat dogmatic about this, but I just don't like any of the circa PHP 4 frameworks. Kudos to them for being forward thinking in the days when PHP oop was garbage, but CI, CakePHP etc, were all written in PHP4 days, and while they may have gotten cosmetic upgrades, are still PHP4 for the most part. In some cases, the ORM choice does not work for everyone, and some of the frameworks were only written to their ORM choice, whether that be an integration or a custom built ORM. Of course there is nothing preventing you from writing nice clean PHP5 classes on top of them, but I'm not impressed with the claims of "hey this is so much faster because we have lean high performance implementation" when what they really mean is that their framework isn't oop, and hasn't been rewritten from the days when everything in a php4 class was public, and you couldn't use object access syntax embedded objects, and PHP made a copy of the object when you did new() or a simple assignment. . I had a gallery plugin that was highly used in the Joomla 1.0 days. When Joomla 1.5 was released it was no longer compatible -- and since neither I nor anyone else with the project was interested in investing the time to do the extensive rewriting needed to make it work with the significant API and structural changes for 1.5, that project is now kaput. And I would be the first to say that it needed to go away, and be replaced by a project that was coded to these new standards. Some of these ancient PHP frameworks probably should also ride off in the sunset, but the adherents, who won't take the steps to redo them other than bandaid them, are quick to defend them hiding behind spurious performance claims, using benchmarks that are atypical to the extreme, and really besides the point. It's easy enough to research the frameworks and take a look at the code you write and ask yourself if on a longer term project, where you forsee yourself doing extensive customization and enhancement, whether or not that framework is structured in a way that the investment will result in robust software that will be maintainable and bug free. Often I believe that what people gravitate towards in some of the older frameworks is their surface level simplicity. They're struggling just with how you get started, and something like symfony or Zend framework is daunting to them, because there's a larger investment in time required. I worked with a guy on a project where he had a prototype of it and it was just a mess, and I suggested we rewrite it in a framework, so I did a quickie zf version of it. He was intimidated by ZF, and so he rewrote it in Cakephp, which was fine for the superficial issues that I'd enumerated, but then when we got into some of the things that he actually needed to do to really solve his business problems, not only was there no documented CakePHP solution, but he was actually having to go in and hack the framework itself, and after a bit I finally said.. this is why I didn't use CakePHP from the get-go. But to him, he was wedded to it, despite the fact that it wasn't really a good platform for him to build upon, simply because he didn't want to learn something he saw as more complicated, purely because he didn't really understand OOP or design patterns enough to see a difference. On another project, there was an app that was again a complete mess, with everyone agreeing that it was unmaintainable, needed an MVC badly, as well as a lot of other structure, and features to get it ready for market. As I was one of the first people to bring this up and say.. ya know we could shoehorn in ZF here, and then I went and actually did some proof of concepts, and implemented a required feature using a ZF class, I found that there was a number of other engineers, all of which from my point of view were the most knowledgeable and productive who agreed that ZF made sense, especially because it could be used ala carte and have things migrated in piece by piece rather than having to do a big bang conversion. Then there was a long really annoying debate with some of the least productive people complaining about how "big" ZF was, and how other frameworks were "faster" even after I repeatedly pointed out that just because ZF has classes to do all sorts of things that the other frameworks didn't and that this didn't matter at all because we would include exactly what we needed and nothing more, I eventually lost the will to continually defend my position. Eventually people began to write their own version of an MVC and config classes and other crap that was easily available in ZF with unit tested code of decent quality, rather than stuff that did 1/10th of what we could have had from ZF without us writing any code. I had even done a view class and pointed out that it had functionality out of the box to support customizable templates, along with a proof of concept. I then had to again endure discussions of how ZF was too heavy and they heard that CI was much faster, even though nobody would ever get off the dime and actually do a version of any of the apps or modules in CI. Ironically, i went on to find other ways to invest my time other than work on that project, and now that some months have gone on now, they still have yet to implement the customizable templates that supposedly were a must have for customers. There's nothing worse than working with people who naysay solutions that provide flexibility and good functional design, and set people up to succeed, all in the name of "that's going to be too slow." These same people never ever profile code, and are almost inevitably are completely wrong about all their assumptions in regards to the eventual bottlenecks of the application. They do manage to be incredibly successful at building really crappy and limited applications that can't be enhanced because they were designed in really convoluted and limited ways, all in the name of "good performance". I'd opt any day for a framework that has really embraced oop and implemented design patterns, rather than one that is antiquated, and has limited support for PHP5 oop. I've worked on some really large (large number of simultaneous users) applications and scalability is a lot more complicated than an mvc, and typically the frameworks that argue that they are "faster" do so, because they're very limited, and work great for simple applications but leave people flailing once they realize that there's no flexibility to them.
  19. Just to close this out... yeah in shared hosting you can't change settings like memory_limit, nor can you restart apache. I have no doubt it was a memory issue.
  20. You can insert multiple rows in one insert by adding to the VALUES LIST: insert into tbl (a, b, c) VALUES (1, 2, 3), (4, 5, 6), (7, 8, 9) This example would insert 3 rows at once.
  21. I want to 2nd DavidAM's advice. One thing I would add is that the calculations you are doing in your SQL like AND WEEK(thedate) = WEEK(NOW()) AND YEAR(thedate) = YEAR(NOW()) Mean that mysql can not use an index on thedate. You want to change this so that you arrive at a date range and you can do specific "between" queries as he suggested. There's no reason why you can't do those sorts of computations. I have a couple of articles on mysql datatime functions on my blog that might help spark ideas of how to rewrite your code. http://www.gizmola.com/blog/archives/blog/archives/51-Exploring-Mysql-CURDATE-and-NOW.-The-same-but-different..html http://www.gizmola.com/blog/archives/99-Finding-Next-Monday-using-MySQL-Dates.html
  22. Relating tables just means, having a column or set of columns that allows you to join one table to another. These are typically the primary and foreign keys in a table. The valid relationships you can have are 1-1 or 1 to many. There is a logical many to many relationship that you can resolve in an rdbms with a table between the two tables that have the logical many to many, each which provides a 1-Many. Look into these terms, and hopefully you'll get an idea. This tutorial from the mysql site might help as well: http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html
  23. Sure glad to help. Often people use a config file like a .xml or .ini or similar. I personally try and have my php application configs be plain php arrays that I can include, because it limits the overhead, but the .xml is certainly a legit way of handling that problem, and certainly will offer good documentation, readability and maintainability.
  24. Don, No, SQL is non-procedural. It actually works with set theory (intersection, union, cartesian product, etc) with the most fundamental concept being that it will always return a set. There are some small procedural additions, and most of the rdbms's have support for stored procs and triggers, but those are advanced features that aren't pertinent to your question. When you start out, all you're really suppossed to be concentrating on is how to get a final result set that provides the data you're looking for, perhaps sorted and grouped. In a way however, thinking about how the final result set might be arrived at in the way you described isn't that off track, because the query engine has to take your SQL, parse it, and determine a query plan. This is what the EXPLAIN EXTENDED feature gives you insight into. There are some concepts you might want to look into that help a lot in understanding how mysql works: -Joins between related tables should be on keyed columns. -If a column appears in a where clause and it is significant to limiting the result set, then that column needs to be indexed/keyed. The main index type of all relational databases is a balanced b-tree index. There are some databases that will substitute a hash index. In either case, the property of these indexes is that they locate a particular value quickly, even when the total universe of values is very large. In order for these to work effectively, the values need to be "high cardinality". So for example if you have 10,000 rows in a table, and you have a column called tbltype that is one of 3 possible values (a, b, c) chances are an index on that column will not be useful because it's going to be low cardinality. The engine will decide that it's better to just scan through the entire table sequentially looking for the appropriate value. Usually if there are queries like that, there is some other column as part of the criteria that is high cardinality that will already provide a minimal subset of rows. The other thing to look out for is doing computation on a column using the built in functions, as you're doing in your query above with the math computations. Since those are derived columns, there is no way for mysql to use indexes if it might otherwise be important to do so for subselecting the table, because the computation is not static. So when you have a WHERE somefunc(columnA * columnB) It is difficult for me to just look at a query, without having the specific information about the schema and indexes, and offer much advice on a slow performing query. However, again if you can bag one of these slow running queries (just echo the query out in an html comment, grab it, and then run the EXPLAIN EXTENDED query in phpMyAdmin or mysql command line client) and copy and paste the result back here, I might be able to offer you some specific insight and suggestions on how to improve it.
  25. Nice clean code for that in the markup, and transition effects as icing on the cake. The other great thing about jquery is that it has been built to work across browsers and versions and degrade as gracefully as possible.
×
×
  • 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.