Jump to content

Crashthatch

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Everything posted by Crashthatch

  1. I think maybe you still need the line: header("Content-type: image/png"); before you do the readfile(). If that doesn't work, try to debug and see where it's failing by visiting the script in your browser and seeing what you get sent (ie. visit the page for that script, then right-click -> view source).
  2. 1) Should it be $_POST rather than $_post ? 2) If you have that posted part at the top of both page 1 and page 2 you'll get this problem: At the very start of your script (on page 2) the $_SESSION['leafshape'] variable will contain the correct value which was set on page 1 (you can check this by putting in var_dump( $_SESSION) immediately after the session_start()), but you're immediately overwriting it with the (now empty) $_post['select1']. You need to check if $_post['select1'] is empty, and if it is then don't include the line: $_SESSION['leafshape'] = $_post['select1'];
  3. The imagepng() function can take a second argument- a filename to save the output image to, rather than outputting to the browser. You could use this at the end to save the output image to a cache directory (eg. with a filename of the form "sheet-xoff-yoff-width-height.png", so "Hyruletown-20-70-100-100.png"), then next time that image is requested check to see if the image exists in your cache and if it does, then just output the saved image rather than doing all the opening / image manipulation / copying etc. that you're currently doing. If I was doing this, I'd actually have an admin "createcache.php" script which would generate all of the possible cached images from the sprite-sheets, then in your page that users would see you could just have normal img tags to the cached images (eg. <img src="cached/Hyruletown-20-70-100-100.png">). This would mean that it's only one static image call for each image, which is much faster to serve than including PHP in any way. In both cases, you'd have to remember to clear the cache directory (and run createcache.php again) after you uploaded new sprite sheets to stop the old cached versions being displayed. Alternatively, just edit / upload the individual sprite images directly rather than using sprite-sheets (what benefit do you get from using these?)
  4. Assuming that the 'account_number' field in the transaction table contains the customer_id of the customer making the transaction you can use a join (read Shp0ngi5's link for more information): SELECT customer_id, tran_ID, full_name, amount FROM transaction_table LEFT JOIN customer ON transaction_table.account_number = customer.customer_id
  5. Generally you'll find that doing it with a single query with JOINs is faster because it's less round-trips to the database. Each mySQL query has an overhead cost (a fixed time latency between the PHP and mySQL server, say 0.01 second), so doing 3 queries takes 3*0.01 + mySQL processing time (say, 0.0001 second). = 0.0301 seconds. Doing 1 query will take longer to do the processing, but saves you massive amounts on the overhead costs: 1*0.01 + longer mySQL processing time (say, 0.0005 seconds) = 0.0105 seconds. I've made up the numbers here to illustrate my point, but unless you're running a very complicated query, the processing time will be less than the overhead of making a query. The numbers here also ignore the extra processing you'd have to do in PHP in the first case. There are probably times that doing stuff in PHP could be faster, but they're so uncommon it's not worth worrying about. Always try to do the minimum amount of queries.
  6. Yeah, anything sent using flush() is ignored. Oh well, I'll try and find another way to do it. Thanks to you both anyway.
  7. How would that help? That'd just save it to the end, then output it all then wouldn't it? I need to output a message, then continue to process, and not output anything else to the browser.
  8. I think the root of the problem is the database design. You shouldn't be storing more than one value in a single column (oh, and it's column, not collum). If you were storing each of the values currently in user_class in separate columns (or if there's an arbitrary number of them, in another table) you could use "joins" to match rows together and only return rows which have a match in both tables. My advice is to read a little on Database Normalization (Wikipedia probably has a great article on it). It'll help with database design for the future, and certainly help you to solve this problem. Note that I'm not saying there's not a way to solve it this way. There's almost certainly a method of doing what you want without creating more tables and things, it's just not the way I'd do it (And I think my way would be more elegant and faster).
  9. I have a script which takes up to 30 seconds to execute. The script generates an image. I need to send a message to the browser so that it thinks the page is complete within 10 seconds. Ideally, whenever the script starts to run, it'd output a message saying that the image will be created soon, and the browser would stop loading the page, then the script would go on to create the image (and obviously not output anything else to the browser). A bit more detail: I'm actually making a page which will be loaded through another website (Facebook). However that site will hit my script, then only wait 10 seconds for the page to finish loading. If my page takes longer than 10 seconds to load, Facebook times out and prints an error message (and anything that was sent from my page is ignored). So even though my page is only generating an image which isn't even used on that page, Facebook times out while waiting for my script to finish. Is there some kind of PHP function sendEndOfPage() or something which would stop it waiting, and just print "Your image will be created soon"? OR, a function like include() but which doesn't wait for the included page to finish- it just starts it and carries on. That way, the 1st script could call a 2nd script and then finish while the 2nd script does all the work behind the scenes. Any other solutions would be welcomed. Other than using cron (which would require quite a lot more work) I don't have any ideas. Thanks in Advance.
  10. I see what you mean. In this case it is just 2 values, but I'll bear it in mind for the future. Thanks for the help.
  11. One example is in a game I'm writing. Vehicles can either be in the air (eg. a plane) or on the ground (eg. a tank). I use a field "inair" (1 or 0) to determine whether the vehicle is currently airborne. This is then read any time anyone looks at the map. There are other places too, (building under construction or fully built? weapon has bombard ability?) but I don't see how any of them are any different. I'll have a look at the bit field.
  12. Sorry about the double-post. Phpfreaks was loading very slowly and eventually gave me an error message. I assumed it hadn't posted the first one. See [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=94931\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=94931[/a]
  13. I need to store a true/false 1/0 value in a mysql database. Originally, I always used a tinyint field type (1 or 0). Next I discovered Enum and, thinking it would only take 1 bit rather than 8, switched to using that. (smaller files, faster search time). I recently read that Enum takes a minimum of 1 byte per record, so there's basically no advantage to either method. Is there a preferred way of storing boolean values in mysql tables? What is it, and why is that method better?
  14. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]If you are joining tables, don't use SELECT x.a, y.b FROM table1 x, table2 y WHERE x.id = y.id AND x.c = '$somevalue' use the more efficient syntax SELECT x.a, y.b FROM table1 x INNER JOIN table2 y ON x.id = y.id WHERE x.c = '$somevalue'[/quote] Thanks (for this bit especially). I've been using the first way all the time. I'll go read up on this (for joining more than 2 tables at once), and try to change most of the queries. As for selecting only the fields needed- I've been doing this where it would have the most effect, but not for if I need over (about) 50% of fields. Are you [i]always[/i] better only getting the fields you need? Say I have a table with 20 fields and I need 18, would it be faster to select all the 18 fields individually, or use *? And I really meant on a dedicated server. I'm going to start off on shared, but I imagine I'll have to go to dedicated fairly quickly if I get a lot of users. Is there any way of predicting the times if I say I'm going on a dedicated server of a certain spec?
  15. Perhaps surround the query with "if(isset($_POST['package']))" instead of the switch? That way the query only runs and the field is only updated if one of the radio buttons was selected. A "case null" where you set $skipquery then only do the query if $skipquery not set would be a slightly longer way of doing it.
  16. I am developing a web-based game written in PHP using mySQL. For development I'm using my old Pentium 3, 450Mhz with 256MB RAM running Windows 98, apache and PHP 4.3.9 The page in question takes 0.4 - 1.5 seconds to generate on this system depending on how advanced that person is in the game. This is with only me using it, and accessing one page at a time. The database is also currently almost empty. When it goes online, there will be many people at various stages in the game- I need to know if the page generation times will still be acceptable. How would I go about working out what the generation times would be on a better server with more in the database, and many people using it at once? (eg. Does 10 people using it at once decrease the speed by 10 times? If I double the number of records in the database, will this halve the speed?) Also, what would be regarded as acceptable? What sort of time should I aim for? Any help or knowledge from past experience in this area appriciated. Thanks.
  17. Cheers guys. I messed around in PHPmyadmin with quotes and spaces, then changed it to: $old_location = mysql_fetch_row(mysql_query (\"SELECT location FROM qu_user WHERE user = \'$cuser\' \")); I\'m sure I\'ll be back soon when I get another problem. \'til then.
  18. How do I use the mysql_fetch_row function? It seems to have worked in all of my other scripts, but not in this one. I get this error: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:webpageswebphpquestmain.php on line 20 This is the offending line: $old_location = mysql_fetch_row(mysql_query(\"SELECT location FROM qu_user WHERE user=$cuser\")); I try to print the result like this: echo \"You have moved from $old_location\"; The same goes for mysql_fetch_object. I have a feeling I have overlooked somthing really simple, but I cant figure out what it is. Any help appriciated, thanks.
×
×
  • 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.