Jump to content

svivian

Members
  • Posts

    86
  • Joined

  • Last visited

Everything posted by svivian

  1. I think Jenk was responding to the "PHP Shell script" part - a user uploading such a file wouldn't be a problem if you served the file as a download rather than letting the hacker point his browser at the url and running it. Regarding the 2000+ files... easiest thing is to split into folders based on the date the file was uploaded, such as year/month. 2007/11 2007/12 2008/01 ...etc
  2. Worked on this a little more; now I'm confused again How would this work with, for example, a single blog post? Like the 'permalink' feature in most blogs? You'd want a URL like index.php?module=blog&postid=123 and in the db you'd fetch the record with this id and display the whole post. We can't call $obj->$action(); anymore. I can't see how to do this with the current system without making "non-generic" changes to index.php, like "if we want to view a full post, we need to check for an extra variable".
  3. Wait, is it because the new blog_model initialisation is not inside a function, eg constructor? I thought you could declare variables in classes outside of functions? EDIT: okay looks like only constants can be declared outside of functions, everything else should be a constructor. Think I've got it working now
  4. Thanks for this post, I think I'm getting the idea of MVC now. However, I've tried implementing thorpe's code but it doesn't seem to work. I get an "unexpected T_NEW" error with the line from the controller: private $model = new blog_model(); Removing the 'private' (does PHP have public/private methods? I didn't think it did) gives me an "unexpected T_VARIABLE, expecting T_FUNCTION" error. Any ideas? (NB I haven't used the code 100% straight, I filled in the few missing bits.)
  5. You wanna have your 'count' function in the SELECT clause, then a conditional on that in a HAVING clause. The basic format is: SELECT COUNT(field) AS total FROM table HAVING total>50
  6. OK fair enough. I'll use the solution posted above. Thanks for the help, everyone.
  7. I don't understand, what would the two queries be? As far as I'm aware, besides selecting all episodes in one go and using PHP to sort them out, the only other way would be a query for each Season (19+ in the case of The Simpsons!) Barand's solution is pretty good though, I think I did something like that for something else but it came out a big mess of PHP code but this is neat enough.
  8. Because each database/table/field can have a different collation. Sorry what I meant was why can't it decide how to input data based on the collation of each field? i.e. if one field is UTF8, input in UTF8, and if another field is ISO-8859-1, input the data in ISO-8859-1 ? Though actually my original question still sorta makes sense - currently if I have a database with ISO-8859-1 collation, any utf8 fields are input in ISO-8859-1 anyway. So it wouldn't really be any different if a database with utf8 collation input in utf8 by default...
  9. Well yes I do, good point. I always try to minimize queries, so given that the majority of pages use select and no inserts it's not necessary for every script. But it won't hurt. It does seem a little pointless in any case...why can't PHP/MySQL do this automatically when it detects the db is UTF8?
  10. I have one table with a basic structure of item (varchar), type1 (int), type2 (int) and a second table of types with id (int and name (varchar). The type1 and type2 fields of the first table link to the id of the type table. There will always be one or two types; if there is only one type set the second will be 0. I want to use a join to display item and the two types as text. I checked the forum and found some stuff on aliases. So far I have this query: SELECT item.name, type1.name, type2.name FROM item, type type1, type type2 WHERE type1.id=item.type1 AND type2.id=item.type2 However this only selects items where both types are set. Is there a straightforward way to fix this query? I've used conditional stuff in Oracle, which I guess probably exists in MySQL, but I'd like to avoid it if there is a simpler way. Thanks to anyone who can help!
  11. Thanks, that worked. Does this mean I have to do a "SET NAMES utf8" query in every script that needs to insert/update data? That might get a bit annoying...
  12. I think you just need count(row) rather than count(group(row)) but I'm not sure. Can you explain in more detail how you want that output (3,3 / 5,2), where you're getting those number from? Do you want to obtain the number of times each UserID is used?
  13. Here's the code I use: $result = mysql_query( "..." ); while ( ($row=mysql_fetch_assoc( $result )) != false ) { echo $row['field'], '<br />'; } mysql_fetch_assoc returns an 'associative' array so you can reference your fields with, in your case, $row['Year'] and $row['Rain']. Inside the while loop you'd put your code to output whatever HTML you need.
  14. I have a text file in utf8 that I wish to add to my database. All the tables, fields and the database as a whole have been set to utf8. But when I read the text file and add this to the database, accented characters come out as gibberish. Have I missed a step here? Do I need to tell PHP explicitly to read the file as utf8 or something??
  15. Thanks, the simple = thing worked. The field is definitely a date field, still don't know why it doesn't work on the earlier version of MySQL but is works now, that's all that matters. Final 'order by' clause: ORDER BY date='0000-00-00' ASC, date ASC
  16. OK this was working on localhost but it's not working now I've uploaded to the internet, My host has MySQL client version 4.1.22. According to the MySQL manual, the STRCMP function existed in this version. I just ran a query with SELECT id, name, date, strcmp( date, '0000-00-00' ) ... and this returns 1 for everything, whether a real date or '0000-00-00'. Any idea why this might be?!
  17. If the id is unique (or you're only ever going to want one entry) you can add "LIMIT 1" to the end of the query. This means that MySQL will stop looking for matches after it finds one. Also if your id field is an INT (which it ought to be, rather than any text-based field eg varchar) when you don't need the apostrophes around '1': SELECT * FROM attendance WHERE `id` = 1 LIMIT 1 Regarding the *, you can select just the fields you need by naming them, comma-separated, eg: SELECT field1, field2, field3 FROM attendance WHERE `id`=1 LIMIT 1 Even if you're selecting all the fields this is not a bad idea because if you add a bunch of fields to the table in the future you won't automatically be selecting them unnecessarily. And indexes are used to speed up queries. I don't know all the details, but essentially some data is stored separately, like an index in a book. It's a good idea to index fields that are often in the 'WHERE' part of your queries, like your id field and fields you are searching on.
  18. Ah, found a solution: ORDER BY strcmp(date,'0000-00-00') DESC, date ASC This works since strcmp(date,'0000-00-00') is 0 if the date is '0000-00-00' and 1 if a "higher string" (later alphabetically). So everything with a real date comes before that without from the first ordering, then the second ordering takes care of the entries with a date.
  19. I have some data I wish to sort by date (ascending), however, some of the dates are missing and thus have the default '0000-00-00' as their entry. When sorting in ascending order these appear at the top of the list, is there a way to put them at the bottom of the list but still have the rest in ascending order? (I know I can do two queries but I'd like one if possible.)
  20. I've installed Linux a few times on my old PC so I'm familiar with the process of creating blank/unallocated space on the end of the hard drive for it. I'm not going to spare more than 20gb for now (for Ubuntu, btw), but it may be quite possible that I'll switch to it on a more 'full-time' basis, given that the more I use Vista, the more I hate it So I'm wondering, what if I want to increase the amount of space for Linux later? Can I add space "before" where it's installed? Will this mess things up? Also does anyone know if it's possible to write to my Windows partition from Ubuntu? I couldn't with my previous distro, Suse, the Windows part was read-only. Perhaps there is a way to change this?
  21. Hmm, well that could work for this, but in general there isn't really a way of knowing how long the final query will be. I've had another idea, which is this query: SELECT Season, GROUP_CONCAT( Pcode SEPARATOR '\n' ) AS Pcodes, GROUP_CONCAT( EpisodeName SEPARATOR '\n') AS Names FROM `episodeguide` GROUP BY `Season` A bit simpler since it doesn't add all that HTML. I can split each result by "\n" in PHP and get an array.
  22. I am trying to generate a neat list of Simpsons episodes for my web site, grouped by Season. I used this MySQL query: SELECT Season, GROUP_CONCAT( '<li><a href=\"episodes.php?episode=',Pcode,'\">',EpisodeName,' (',Pcode,')</a></li>' SEPARATOR '\n') AS Episodes FROM EpisodeGuide GROUP BY Season The idea was to generate some HTML quickly to avoid lots of looping etc in PHP. But I found that GROUP_CONCAT truncates results to 1024 characters. Is there a better way to do this? There reason for grouping is because I want to do something like: <h2>Season 1</h2> <ol> <li>[Episode Name]</li> <li>...etc</li> </ol> <h2>Season 2</h2> ... which I don't think can be done easily with a simple select all rows query. The only other way I can think of is to use one query to get the number of Seasons, then a query per Season to list the episodes...but this seems like overkill. Suggestions welcome!
  23. Ah, nevermind I've found a better solution: __FILE__ This always returns the name of the file it's in. For reference, here's how I get the folder: <?php $included_file = str_replace( '\\', '/', __FILE__ ); // to fix Windows $included_directory = substr( $included_file, 0, strrpos( $included_file, '/' ) ); ?>
  24. Forgot to mention that. It won't work in all cases since $_SERVER['DOCUMENT_ROOT'] gives the same value on a domain and subdomain, e.g. www.example.com and site.example.com - but the real document root for each site is different. This is for a script I'm writing to release to the public. So in addition, the subfolder could be anywhere in the site structure (the text file will always be in the same place relative to the subfolder); I need to be able to detect the folder automatically.
  25. Is it possible to find the path to a file relative to an included script? For example I have one file, test.php, that includes another in subfolder/config.php. The config.php file stores a relative path to a file I want to read, eg $file = 'data/file.txt'; If I open config.php the file is read without trouble, but if I open test.php the file can't be found. Is there a way to make sure I always find the file, regardless of which files include config.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.