Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. Querying the database every 5 seconds will most certainly put a substantial load on the database. What is the data, and why do you need to query it every 5 seconds?
  2. A sql injection is an exploit, where someone who is using a web application is able to inject some SQL code into a script, that was never intended by the developer. What you're doing has nothing to do with sql injection. So I looked at your code, and I have a couple of comments that might help: -First, when you fetch a row using mysql_fetch_row() you get an array that has the columns in the result set both in numeric order, and in associated keys. It's usually best to specify one or the other for efficiencies sake, and I strongly recommend using the associative version. There's a wrapper around this function that makes it even easier: mysql_fetch_assoc(). Then you write your code like this: echo $row['name']; rather than echo $row[2]; It's a lot better code documentation and also won't be broken if you alter the structure of the table which could effect the order of the columns in the table. The other comment, is that you are suppossing we know what your database looks like, but we don't. When you have a query like 'SELECT * from table1' we can't read your mind and debug your issues when we don't have any idea what the database looks like.
  3. Onedumbcoder gave you the sql syntax which works fine, and will be optimized so long as the prefix column has an index on it.
  4. Well there are many different template systems, but quite a few will do parsing and replacement using the {} to mark a block. In this way it's easy for designers to use html and then have blocks that come from php inside the markup. If this is framework code, you need to find where the .tpl file is being specified and see what code actually renders it. If it's a Model-View-Controller system, this will probably be a "view" class, and the items inside the curly brackets will have been injected into the class or class scope in some way, so that when the template is rendered, those items can be replaced with the content of the corresponding variables.
  5. We'd need a bit more context than that. Is this a template file? (.tpl)
  6. Amen. Sadly I worked for the Entertainment business for many years, and the thinking inside it is: The consumers will buy and rebuy our product -- we controll it. It's a really anti-consumer posture, but I believe there's a lot of new thinkers that are starting to make it into management. I think we'll start to see more packaging where you can get multiple versions of a product if you buy it, because sales for DVD's have been dropping off a cliff and Blueray has not enjoyed the uptake they were hoping for.
  7. I don't have a problem with the guy losing the case. What's ridiculous is the damages. However, the guy in question, could have settled this case long ago for 5 grand. In fact the RIAA has stopped with these lawsuits, and only 2 of them went to court. I think what happened is more a reflection on the way the legal system and copyright law has been slanted absurdly towards the big business copyright holders. The damages were designed to prevent piracy, and there are any number of lawyers who believe that without a profit motive, there's no damages that can be assessed. One of those people, is the lawyer for the guy in the boston case, who was prevented from presenting a "Fair Use" based defense, and plans on taking this up on appeal. On a related note, there's a story on NPR right now about one of my favorite bands, The Posies. The main band is two guys who wrote all of their songs, and one of them, Jon Auer, talks about in the story, that their best selling album "Frosting on the Beater" sold about 250k copies. It was in fact their 2nd album, while they were signed to Geffen records. Auer says in the story that he never saw a check from the Album. 250k albums sold, and they never got a single penny. They did one more record for Geffen, which didn't sell well (but I can say without any hesitation is an incredible album that could have had several hits if it had got any promotion or radio play, which it didn't). Then they made an independent album, which sold only about 25k copies, and yet they actually received money for that album's sales. I think a lot of bands are now wise to the music racket, and understand that the big record company contracts are designed to fleece them. The days of becoming rich off record sales are fading into the sunset, for all but the multi platinum sellers, and even those people have horror stories -- like Bruce Springsteen who didn't make make any money off his first three albums which include Born To Run. I don't think it's as black and white an issue however. Movie Studios and big record companies are willing and capable of pumping thousands or millions of dollars into promoting an artist. They gamble knowing that the odds are against them, and so they fix the game so they still are able to recoup and profit off the 100-1 odds. CD royalities for artists are a joke for the most part, but even if they weren't, the problem is that for the 99 artists who don't blow up, they end up with very little from record sales, although this may still be worthwhile if it allows them to have a career and tour. BTW, this little article does a great job of talking about the way the music business works, and some of the current royalties issues: http://www.geeksaresexy.net/2009/07/21/music-royalties-for-dummies-or-ascap-is-not-the-riaa/
  8. I have a theory. What is the type of the registrationDate column? Is it a DATETIME or TIMESTAMP? If so, there is your answer -- you have registrations that occurred in the last 23 hours and 59 seconds of the last day of the month.
  9. Is this really solved if it doesn't work? If you could answer the questions I posed, I might be able to give you better advice. Also, it doesn't seem like you're reading what I wrote, as you still are mixing the group by and DISTINCT which is not needed or helpful. Once you GROUP BY restaurants.ID, you get 1 row per restaurant. That is guaranteed, however the inDate you get is not predictable. Usually when you GROUP BY, you will do this to utilize a summary operator, like MAX, SUM or COUNT.
  10. No problem. I have had to solve similar problems, so the question of usability is an interesting one. Probably the most intuitive way is to have an images screen that is associated in the admin system with a particular moth. From this screen you should be able to: -Add new image -Replace existing image -Delete image -Check box image as thumb -Order images For uploading images, you might look for some help in terms of pre-built upload class(es). If you roll your own you'll probably find there's quite a lot of details involved -- not a bad exercise, but expect to learn as you go. Read the php manual carefully about the $_FILES and move_uploaded_file() at minimum. One thing I found useful was to to do some file renaming. Basically I took the sequence of the picture row being created, and changed the image when it gets stored on the server to be seq_name.ext. I also did things like lowercasing the name and removing spaces etc. When I generated thumbnails, I could then name them seq_name_tn.ext. One last thing to be aware of, is that if you expect to have a really large number of these images, on a unix filesystem, things will slow down significantly if you reach a certain threshold of files in one directory. So a great way of breaking these up is by setting up a subdirectory structure in advance, named 0 - 9. So your dir structure could be: /images/0 /1 /2 ... Then you simply use the last digit of the sequence # to determine in which directory you should store the file. One other gotcha is that you may need to adjust things in the apache configuration regarding maximum post size, and the php.ini to allow uploads and to modify the max uploaded file size. This pretty much depends on the size of your source image files. Primarily however, it's simply built on an input form element of type "file", and the form "enctype" needs to be "multipart/form-data". The rest of the magic takes place inside your serverside code. Since you're dealing with images, you might find that the exif extension is useful for verifying the contents and size of images.
  11. I agree with Corbin -- each class should have its own file if you follow the pear/zend framework guidelines. You could package these by putting them in a directory structure. Take a look at what Zend framework did, because that's a great example of a framework that was also designed to be used as a library ala/carte.
  12. gizmola

    Race

    Hijacking this thread Do you live in Ireland? I'm just about to embark on a trip there for a wedding.
  13. This is improved since the previous version. I like the basic color scheme, and you don't see earth tones uses that much, which I think could be appropriate for a vet. So, some criticisms: You use way too much "above the fold" space in the header. Some suggestions: -Shrink the verticle on the Dog. I know that Might be tough, but it's just way too much space wasted on a picture. -Move the Cat cutout up so that it overlaps the text more, to conserve space. Add a rollover effect for your top bar menu. Finally, the slogan is kinda clumsy: "where the pet's best interests are at heart". If you want to go in this direction I'd suggest a more direct rephrasing. "at heart" doesn't really work with the phrase because "best interests" is an intellectual pursuit, not an emotional one. You might also consider words like Humane, Caring, or Loving if you want to link to emotion. 'Minding the best interest of your pet' 'Keeping in mind your pet's best interests' etc. Are other alternatives that might work better.
  14. Yeah I didn't see that before, but it looks like your where clause in regards to inspections.inDate is wrong. The other thing here, is that if what you really want is to use the GROUP BY, then there's no need to use the DISTINCT and vice versa. Pick the approach that makes sense for you. If you want the indate, then use the GROUP BY only. What you're attempting now, if I understand it, is that you only want to see restaurants where they have not been inspected in the last 30 days? The approach you're attempting to use is not going to work without some adjustments. Also, could you indicate the mysql datatype of the inDate column?
  15. If you are inserting a species AND a picture at the same time, then it's a 2 step process, nothing magical about it: -insert the species row first -- Use the appropriate mysql function/method to get the ID (last_insert_id() or ->insert_id() -insert into picture, specifying the value you got from the insert_id above as the foreign key. This is one place where mysql works a bit differently compared to a lot of other relational db's. For example oracle has a seperate sequence object that basically gives you unique id's that you can get in advance of a query. Mysql, you have to accomplish the insert, then see what it gave you. This actually works fine, because each mysql connection has it's own thread and queries are serialized on the connection, so there's always one "last id", even if you reusue the connection for a variety of queries. You can of course seperate this more fully in your code by making multple connections to the database. What a lot of people like to do, is have one connection for selects and one connection for data maniuplation (insert, update, delete). You can even add some db security in this way by having totally seperate connections for each, with the select connection using a user that only has SELECT privileges on the table. Well-- just musing at this point. Hopefully you got the basic answer in the first part of the comment.
  16. Yeah it seems to me a simpler way of deriving the grade would be: Start with $correct = 0; For each case $correct++; At the end, $score = round(($correct*100)/15);
  17. Yes, this is pretty much a classic 1 -> Many relationship. One "species" row can have related to it, Many "pictures". When you make a 1-Many relation, the table on the "Many" side receives a "foreign key" (the primary key of a "foreign" table) in it. Personally if I was going to build this in mysql, I would design the tables as such: species --------- species_id int unsigned AUTO_INCREMENT primary key name varchar(60) description text picture --------- picture_id int unsigned AUTO_INCREMENT primary key species_id int unsigned path varchar(255) One thing to understand about mysql is that using the standard MyISAM engine, you have no referential integrity between related tables. So the database will not enforce constraints. It also doesn't have COMMIT/ROLLBACK. If you desire these things, you need to use a different engine. Most people use the Innodb engine for those tables, if that's highly desired. With that said, if you wanted to pull up all the information and pictures for a particular species --- (you'll get a row for every picture, and this also uses an inner join, so if no pictures exist, then you get no rows). $sql = "SELECT name, description, path FROM species s, pictures p WHERE p.species_id = s.species_id AND s.species_id = $species_id"; This is just meant as an example, and assumes that you would have gotten the $species_id, possibly from a get param. Omittting that AND, you'd get a full result set of every picture. If you want at least one row you'd need to change this to use an OUTER join, but I'll leave that to you to investigate.
  18. Replace is a non-standard MySQL extension that has nothing to do with UPDATE really. What it's really focused on is INSERT. It was added to allow people to bulk insert rows into a table, and giving you a tool to deal with problems caused by key violations that might otherwise cause the bulk insert to fail. In essence what the REPLACE does is: -Does primary key of INSERT == Primary key of a row? --- If YES ------- DELETE ROW -INSERT NEW ROW So, when you are doing an UPDATE, and specifying a value to be based on the existing value, you get the behavior you've noted, which is, that the original value get "lost" because that row gets Deleted. So in short, Replace really isn't meant to be a substitute for an UPDATE, and due to the nature of the checks involved, is also going to be slower than an Update. Replace was really added to help people who want to repeatedly re-insert a base set of rows into an existing table.
  19. While Corbin's answer will work, you can remedy your query by fixing the underlying problem. Your underlying problem is that you did not specify an inner join criteria to your query between restaurants and inspections. This results in a "Cartesian Product", or in other terms, you get a result set with every combination possible of restaurants and inspections. This is why, you unexpectedly get what appears to be multiple rows for the same restaurant, because you inadvertantly created rows in the cartesian product, for every ID and inspection. If you added to your WHERE clause "inspections.restaurants_ID = restuarants.ID" or whatever the joining key is between the two (I don't have your schema so I'm just guessing there), I think your original DISTINCT will actually work.
  20. More like Petabytes. If you look around there's quite a lot of information about how google handles things. They pretty much have custom technology for everything, from mapreduce, to the google file system, to Bigtable.
  21. This is not relevant to php5 at all. PHP has always had page script -- all memory is garbage collected once a script is done executing. What has changed recently is the conditiions under which garbage collection inside php is done. PHP is now more aggressive in doing garbage collection during the execution of a script than it was previously. You could certainly think of it in the same way you might think of the way a jvm manages memory, however, in the web context, php has no way to persist data beyond a single http request/response. This is in fact why sessions are such a necessary mechanism.
  22. You can have whatever columns you want in a table. Each individual column can have it's own datatype. Other than that, we don't really have enough information about this application to understand what you're trying to do, or suggest alternatives.
  23. The php core interpreter can be run in two different contexts. One is as a standalone program, and the other is as a webserver module. The command line interpreter is the standalone program. Usually they are both installed when you install php. You didn't indicate what operating system you are running under, but in either case, you want the program to be in the path. If it's windows then the program is named php.exe. If linux/unix it's just going to be php. You would run these from a shell. In linux that's pretty standard stuff, but in windows you'd need to run it either in cmd or command, or use the windows run command to run it.
  24. You use the command line php interpreter to invoke the script -- php -f yourbot.php.
×
×
  • 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.