Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,352
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. is the script using full opening <?php tags or just <?
  2. that 134Mb of memory being consumed is not because of the code you have posted. that's just where the code was running at when memory was exhausted. something else on the page, either the total amount of code and static data, or the dynamic data leading up to the point where the error is being reported at is what is consuming that amount of memory. you need to profile the memory usage at various points in your code to find where the large amounts of memory are being used at. if you would like anyone here to try to see what things the code could be doing to consume large amounts of memory, you would need to post all the code (the problem could be code and static data present after the point where the error is occurring at) for that page, less any database credentials. if you are copying something you found on the web, be advised that most game code found on the web started life as a classroom exercise, to teach basic programming, and are not how you would write an actual browser based game because they typically don't have any proper memory management, don't have efficient code, and aren't written as general purpose code that is easy to configure/change, debug, or maintain. it is always best to just learn how to program first, then write, from scratch, your own code that does what you want, rather than copying things you may find on the web.
  3. a) you need to echo the actual sql query statement, echo $query; you need to do this before the msyql_query() line since that line is die'ing due to the error. b) you need to escape the $each value being put into your sql query statement to prevent sql injeciton and to prevent sql errors. c) it is much easier if you just put each of the keywords like '%term%' entries into an array and implode the array with an ' OR ' to produce the combined term (this will produce the correct result even if there is just one entry.)
  4. your code that detects the change in the categoryname - if ($categoryname != $rows['categoryname']) { ... } is where you would do this. when the categoryname changes (your existing logic), if it is not the first category (if $categoryname is not equal to the initial '' value), you would output a closing </div> tag, then unconditionally output the <div class="category"> tag right before the <div class="h"><h2>Category Title</h2></div> bit. you would also output a final closing </div> after the end of the while(){} loop, if $categoryname is not equal to the initial '' value, meaning that some data has been output. your existing - if ($categoryname != $rows['categoryname']) { ... } would become - if ($categoryname != $rows['categoryname']) { if($categoryname != ''){ // a previous section exists, close it here... echo "</div>"; } $categoryname = $rows['categoryname']; echo"<div class='gallery'>"; echo"<div class='h'><h2>".$rows['categoryname']."</h2></div>"; } and after the end of the while(){} loop, add - if($categoryname != ''){ // a previous section exists, close it here... echo "</div>"; }
  5. your code is testing for error conditions and returning false values, rather than expected data. your code needs to test the returned value, at every step that can fail, and take an appropriate action when there is an error, such as not running the remainder of the database dependent code on the page and to output a message to the visitor. it's actually easier to use exceptions for things like database errors, since you can have several points in the code where an error occurs, but the action you take is the same for all of them. for a database dependent design, any database errors would mean that the page isn't going to function correctly. you should output a user message - 'Sorry, an error is preventing this page from being displayed at this time.' and log (for a live site) or display (during development) all the information you have available about the error - who caused the error (visitor info - ip, loggedin user_id), what occurred - what type of database operation caused the error (connection, query), what the query was, what error was returned from the database, when it occurred (date/time), and where in the application the error occurred (use debug_backtrace). you can handle the switch of where your application detected errors go to by using trigger_error(), which makes use of the php error_reporting/display_errors/log_errors settings, which also control the logging/display of php detected errors. once you have code to handle the errors and to tell you what is going on, you will likely be getting a mysql syntax error that you should be able to solve based on the error message.
  6. all the foreach() loop is doing is giving you the last element in the array. to eliminate duplicates, you need to remove each number from the array as you use them. array_pop() would be a good choice to both get the last element from the array and remove it at the same time. you would put your range() and shuffle() statements before the start of your while(){} loop.
  7. having error checking logic in your code is something you should ALWAYS have, from the start. not something you add after the fact. for development, you would display any errors (both php and ones your application detects.) on a live server, you would log the errors instead and output an appropriate message to the visitor. you can handle the switch of where your application detected errors go to by using trigger_error(), which makes use of the php error_reporting/display_errors/log_errors settings.
  8. i'm going to guess you don't have a column in your table named post and that the prepare() statement is failing with an error, assuming that emulated prepares are turned off, or the execute() statement is failing with an error, assuming that emulated prepared are not turned off (which unfortunately is the default.) well written code is self-troubleshooting. it will tell you when, where, and why it is failing. to get your code to tell you when, where, and why it is failing, your code must have error checking logic in it. you can either add conditional logic to test the result of each statement to find out if it is working or not or you can use exceptions. i recommend using exceptions for fatal problems.
  9. you last reply is not what you stated at the start of this thread and it would appear your last reply is what your other current thread is about. please don't start multiple threads for the same problem and we can only help you when you clearly state what problem you are having with your code.
  10. which of your three columns is the only one that is getting a value and is that value the expected value or is it the complete line from the csv file? short-answer: we are not sitting there with you and when you state something like "it only uploads a single column into my database" we don't know what you saw, but knowing that information tells us where to look at to find the problem. so, it is always helpful to post some example input data you are using with your code, what result you are getting from that input data, what exactly is wrong with that result, and what result you expected to get.
  11. your code contains a fatal php parse/syntax error, because you are missing a closing ?> tag. you need to have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini so that php will report and display all the errors it detects. you will save a ton of time. for parse errors in your main file, you cannot put these settings into your code, because your code never runs to make use of the settings.
  12. you would need to post some example code, but i'm betting you are now talking about links in your html that are loaded by the browser via their URL and NOT things that are being included/required by the php code.
  13. a www has nothing to do with this, as a www is part of a URL specifier, i.e. the host-name/sub-domain. include/require is using a file system path. nothing to do with a URL. the only way a leading / would work in an include/require statement is if the resultant path is to where the actual file being included/required is at, starting at the root of the current disk. but this would mean that all code written in this environment will break if it is moved to a different directory structure. the whole point of having a variable like $_SERVER['DOCUMENT_ROOT'] is so that the code can be put onto any server and it will work regardless of the underlying directory origination.
  14. for the require/include statements you are showing (that don't have a protocol and a domain specified, such as http://somedomain or ftp:/somedomain) you are dealing with file system paths. for a file system path, a leading / refers to the root of the current disk. the confusion with this occurs because for a URL, a leading / refers to the domain root of the current page in the browser, and is a domain root relative URL (as apposed to a relative URL that starts with a . or a..) when the browser finds something in the context where a URL gets used in the html markup, if it starts with a /, the browser takes the protocol and domain of the current page and appends the domain root relative URL it found to form the actual URL that will be used. file system paths on the server and paths in a URL in the html of a page in a browser are two different things.
  15. i would open the downloaded pdf file using your programming editor to see what it has extra in it (look at both the start and end of the content in the file.) you either have php error message(s) or some text content from your download code file. also, where are you setting $pdfName at in your code? and, AFAIK, the filename='...' attribute value in the attachment; header should have quotes around the actual file name to get all browser types to recognize the file name.
  16. if you are going to use sprintf() to build your query string, you would need to double the %% in the DATE_FORMAT() format string so that they are treated as literal % instead of a sprintf() format specifier. however, if you are using sprintf() to build your query strings, you might as well just switch to prepared queries. the %s, %d, ... sprintf() format specifiers are where you would put the prepared query place-holders, so all you would have to do is change them to ?, prepare the query, bind any input data (which are the argument(s) in the sprintf() statement), and execute the query.
  17. your first php tag, isn't one. it's a <? followed by a space, then the php. if you look at the view source of your output in your browser, you will see the raw php code since it wasn't seen as being php code on the server and was sent to the browser as is.
  18. this sounds like the - insert new data, update existing data, problem. you don't need to select existing data first to do this. you can either use a REPLACE query or an INSERT ... ON DUPLICATE KEY UPDATE query. also, your prepare() and bind statements should not be inside the loop and if you are binding input parameters, you would not supply the data values in the execute() statement. edit: i see you posted a reply while i was typing this. for most simple queries, the time taken to communicate the query/data to the database server, which is all done using characters, is much longer than the time it takes to actually run the query. even with a prepared query, assuming you correctly prepare and bind things once, before the start of any loop, you still must communicate the values for the bound parameters. the only way to substantially reduce the amount of time taken for a large number of queries is to reduce the total number of queries and communication round trips (there is handshaking for each communication that also takes up time.)
  19. no case that i can think of. even if you only have two same meaning fields spread out in a row, it results in more code to find or manipulate the correct piece of data. this boils down to the granularity of the data. normalized data stores each piece of same meaning data in its own row. as a result, you can easily find or manipulate any amount of the data, be it one piece, a specific sub-set of the data, or all the data.
  20. you can either do this in the database query, using mysql's DATE_FORMAT() function, or you can do this in your php code, using php's datetime class, format() method.
  21. it doesn't even do that, since you either have to hard-code each field reference or build a dynamic reference to access the incrementing field names. what if you are trying to get the total of any field, i.e. total yards? you have to write a bunch of php code or a verbose query listing all the relevant fields to do it. by normalizing the data, you can do a simple SUM() in a query to get the same result.
  22. go back and re-read what Barand first suggested - what this means is to construct the HTML in a php variable (i.e. replace the echo statements with code that adds the html to a php variable.) when you are done constructing the HTML in the php variable, you can do whatever you want with that php variable. you can echo it on your page to display the html to the visitor or you can use it in the email message body to send the html in the email.
  23. i would get a COUNT() of rows with the same orders.order_id and a SUM() of the line_item.status values for that order that are equal to Dispatched and test if they are the same or not. just the relevant bits of your query, would be - SELECT o.order_id, IF(COUNT(*) = SUM(IF(li.status = 'Dispatched',1,0)),'Completed','Not Complete') as order_status FROM orders o JOIN line_items li on o.order_id = li.order_id AND o.order_id = $id GROUP BY o.order_id btw - as mentioned in one of your previous threads, you need to use table alias names in your query to simplify it and make it more readable. some new-lines would help to format it as well. also, by putting the o.order_id = $id into the join condition, you will limit the rows that get operated on to just those you are interested in. when you use a where condition - WHERE o.order_id = $id, the join condition joins ALL the corresponding rows from both tables, so, if you had 100's of thousands of orders, you would join the 100's of thousands of rows in the orders table to the corresponding rows in the line_items table. edit: you would also not store the result of this into the orders table. it is derived information and storing it will create data sync problems. what happens if someone returns an item and the status for that item changes from Dispatched to Returned? if you store this derived status in the orders table, you must now have more code and queries to update it. if you don't store this derived status, but calculate it as needed, you don't need to do anything extra when a status changes.
  24. that's because the purpose of that query is to get a unique list of city names, to produce the select/option list, that is used as a filter for the actual data retrieval query. that query isn't the one that retrieves the matching data and it isn't where the limit term belongs.
  25. what URL did you enter in your browser's address bar for that page? if you are doing this on a localhost development system, it should have been something like - http:/localhost/yourpage.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.