Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. 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.)
  15. 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.
  16. 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.
  17. 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.
  18. 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.
  19. 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.
  20. 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.
  21. 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
  22. programming help forums are not here to fix your's or other people's code for them. do you have a specific programming question or a specific problem or error that you need help with? we can only really help you when you post just the relevant section of code you need help with, along with any errors or symptoms you got from that code. also, we can really only help you with one issue at a time, that you have isolated out of the complete code. expecting someone, on a general programming help forum, who are not the author of the application in question, to be up to speed with or to go through a complete application in order to help you, is beyond the scope of what you should expect.
  23. back to your original problem, where are you trying to save this text input to? a database? a text file? and what errors are you getting?
  24. the constant() function that will let you dynamically get the value of any constant given a string containing the constant name, which you can dynamically produce. however, it sounds like you need to use an array to hold your related values (the actual values could be defined constants), where you can use the array index to access the correct element/entry.
  25. you already have a thread for this problem and if you had looked where you originally posted it you would see a link to where it was moved. topic locked.
×
×
  • 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.