Jump to content


Staff Alumni
  • Content Count

  • Joined

  • Days Won


Everything posted by mac_gyver

  1. if you do this - you will end up with code that looks like this - $out = ''; foreach($indexed_data as $type=>$arr) { // start a group $out .= "<optgroup label='$type'>"; foreach($arr as $row) { // add the output for each $row of data within the group $out .= "your makdup here for the <option ...>...</option> tag"; } // finish the group $out .= "</optgroup>"; }
  2. that's an acceptable var_dump() output. the length matches the number of displayed characters. i suspect you are seeing the result of two (or more) requests to the page. for the first request, there is an input value and when you are using echo/var_dump to display it, this is preventing a header() redirect, that's causing additional request(s), which don't have the expected input. you are seeing the displayed result from the last request made. this 'works' when you hard-code the value, since all requests have the input value. so, two things - if it sounds like your code is capa
  3. the value probably contains some non-printing character(s). what does var_dump($_SESSION['bid']); show?
  4. you got an sql syntax error message calling your attention to a specific point in a query. did you look at that sql query and attempt to determine what might be wrong with it at that point?
  5. no. the parameters and values in code can come from any expression, such as a literal string, a variable, the return value from another function call, a math/logical operation, ... you would define a data structure (array or database table) that contains a list of the expected form field names (types, validation tests...) you would then loop over this defining structure to dynamically test/validate the inputs. the field name, which would be in a variable, would be used in place of any hard-coded associative field name in the code. except for unchecked check-boxes and radio-buttons, a
  6. as a side note - if you use the PDO::FETCH_COLUMN fetch mode with the fetchAll() method, you will directly get an array of the (column) values, rather than an array of rows of data.
  7. for the $jokes variable to not exist, either the query failed due to an error or there are no (matching) rows in the database table. for the first case, most database statement errors are fatal problems, either due to programming mistakes or the database server not running, and there's no point in code on the page continuing to run at all. therefore, you would want your error handling to display the actual error information when you are learning, developing, and debugging query(ies) and to log the actual error information when on a live/public web server. to do this, simply let php catch
  8. here's a page with a more specific date sort example - http://www.javascriptkit.com/javatutors/arraysort2.shtml
  9. you will get a false return value if an error occurred (you will get a zero return value for no match.) you can specifically detect the false value and log both the $needle value and the debug_backtrace() information.
  10. if you are trying to paginate an array of data, just use array_slice(). it takes the same offset and length values as the LIMIT clause in an sql query would. this would eliminate all this 'glue' logic. you would just foreach(){} loop over the array of data returned. this will also work correctly for a partial last slice or an initial slice with less than ROWS_PER_PAGE elements in it. if this data is coming from an sql query, why aren't you just getting the requested page of data directly in the query?
  11. the value returned from the ->execute() method is - you don't fetch data using that returned value. ->query() and ->prepare() are PDO methods. they both return a PDOStatement object (when successful.) ->fetch() and ->execute() are PDOStatement methods. ->fetch() returns a row of data (or a false if there's no data to fetch) and ->execute() returns a boolean value as listed above. typical code for a non-prepared query - $sql = "build the sql query statement in a php variable"; $stmt = $pdo->query($sql); // fetch a single row of data $row = $stmt-&g
  12. you should allow for multiple stock in events per date. this will assign a 'stock in id' for each event that increases the stock. when you consume stock, you would insert 'child' records, using the parent's stock in id to relate the stock out event back to the corresponding stock in event. if you consume stock from more than one stock in event, you would insert a stock out/child record for each amount you take from each stock in event. to find the earliest stock in event(s) that has(have) an available stock amount equal or greater than a needed quantity, you would join the parent and
  13. it will probably take having all the code that's part of 'it' to be able to help.
  14. you probably have some broken html, prior to that input field, due to the short opening php tags <? being used. when you do a 'view source' of the page in any of the browsers, do you see the raw php code or do you get the values that php is trying to echo onto the web page?
  15. if you index/pivot the data, using the type value as the main array index, when you retrieve the data into a php multi-dimensional array, it is clearer where the start and end of each section is when you then use two nested foreach(){} loops to produce the output.
  16. you should have three tables. the asset table is where the items are defined, with id, name and any other columns needed to describe each asset. this will assign an asset id. you would then have an asset_user table to store the user(s) who have each asset, with id, asset_id, user_id, and any other columns needed to describe the asset/user data. you would then use a LEFT JOIN between the asset and the asset_user table, and a LEFT JOIN between that and the users table, to get the assets, plus any optional user information. If there is no user to join with, you will get NULL values for thing
  17. define: "doesn't work"? exactly what did you observe in front of you that leads you to believe that something about the code you have posted doesn't work? did you get a blank page, a bunch of php errors, a database related error, the output about - No Search Result Found, just some of the matching search results, all the database data was displayed, the displayed data was not in the expected order, did the page just refresh, did it appear like the clicking on the button did nothing at all, or a number of other possible symptoms? knowing what symptom you observed, narrows down the problem
  18. doing a search on the www would be of some help. there are countless examples posted on the web showing all the different skills/parts you would need to build this application. designing code involves defining what the user will see and be able to do on each step of a process. this leads to defining what data, if any, you need as an input, what processing you are going to do based on the input data, and what result or output you are going to produce. when a user browses to your category search page, what will they see? a (get method) form with a text input (assuming you don't want ju
  19. in your previous thread - https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/ you had code that successfully fetched and displayed one row of data. based on the sql query you are showing now, you would want to use that same design pattern, not the design pattern that you were given that operates on multiple rows of data. based on your statements, edit: and the undefined index error you just posted, the get input probably doesn't contain what you think. your code should ALWAYS - validate all inputs before using them. if the get input isn't set or is em
  20. how do you know that, especially since you should be getting a status_id number as the returned value? perhaps there's some problem with the code that's using the result from calling that function? what is the (default) fetch mode you are using for the ->fetch() method call? have you set a default fetch mode yourself or are you using the default, default fetch mode? any chance you have more than one database and are selecting the wrong one?
  21. there are a number of issues in the code that are producing php errors. to get php to help you, find the php.ini that php is using and set error_reporting to E_ALL, display_errors to ON, and output_buffing to OFF. stop and start your web server to get any changes made to the php.ini to take effect. you need to ALWAYS validate inputs to your code before using them. if you are selecting from existing catalog (id) values, you should have some type of select menu and not require the user to remember and type in values. another recommendation is to separate the database specific cod
  22. to get php to help you, find the php.ini that php is using and set error_reporting to E_ALL, display_errors to ON, and output_buffing to OFF. stop and start your web server to get any changes made to the php.ini to take effect. you should then be getting some php errors when you run your code that will help you find what the problem is.
  23. a. the echoed time values should have been correct. are you sure about the posted code and the output that you got? b. browsers and web servers don't interact in real-time. even if you try to flush() the output, you are not very likely to get the result you want (see the php.net documentation for the flush() statement to see all the problems with trying to do it this way.) c. people don't like to wait on web pages to display things for x amount out time (it's either too long of a value or too short of one to suit the current visitor) or to redirect around on your site. the only redir
  24. no. this results in a bad User eXperience (UX), takes more code, and gets your users used to automatically changing urls on your site, which increases the chance of a phishing site working. the form processing code should be on the same page as the form and the only redirect, upon successfully completing the form processing code, should be to the exact same url of the current page, to cause a get request for that page. any navigation to other pages should be via navigation links that the user can choose where he/she wants to go to. the form processing code would go above the start of the
  • 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.