-
Posts
5,450 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
assuming you have or have written a database based pagination script, it is doing two things. 1) getting a total count of the number of data items, and 2) retrieving the correct 'page' of data to display. to accomplish pagination for an array of data, you would first get all your data into an array, in the order that you want the data. then, to accomplish item #1, you would use count() on the array of data. to accomplish item #2, you would use array_slice() on the array of data, using the offset and length (number of rows per page) values normally going into the LIMIT clause in a database query as the parameters going into the array_slice() statement. you would then loop over the array of data that the array_slice() statement returned to produce the output on the page. to get your array of data ordered the way you want, you can either use php's usort() or array_multisort() statements. examples of using these are in the php.net documentation and posted all over the web.
-
the best method would be to put the information into an array, then use array_slice() to reference a specific 'page' of that information. the array_slice() offset and length parameters function exactly the same as a LIMIT clause in a mysql based pagination query.
-
jazzman, you and the OP are both connecting using ISP's in Toronto. i think the OP intendeds to insert one row of data for each player, per event/match, with the point result for that event/match (or whatever the granularity of the information is for.) if this is the case, there's no 'on duplicate update ...' part needed.
-
does the 'view source' of the html have the expected values for the id='...' attributes? edit: am also fairly certain that when pdo is doing emulated prepared queries (the unfortunate default), that bind statements don't return or throw any database/data releated errors.
-
need help with php payment gateways
mac_gyver replied to tvasconcelos's topic in Third Party Scripts
i think you misunderstand what programming help is, especially if you have received the same response on other programming help forums. we are here to help programmers with their code, hopefully code that they have written, or if they have found it or been given it, that they know enough about the programming language it is using so that they understand what it is doing and can even make an attempt at solving their programming problems or would understand any code given in a reply. a programming help forum should not be your first line of help, it is the last, after you have exhausted all the means available to you. if you have no programming means available to you and you are turning to programming help forums as your first line of help, without having or posting the result of your coding attempt, along with any relevant errors or symptoms, you don't have anything that we can help you with. you are instead asking someone to do it for you, which when it comes to the task of even looking into what is needed to integrate a payment gateway with your existing site, is more than what you should expect to get for free. so yes, someone taking the time to find out what your site database and coding structure is, what the payment gateways return as data, and integrating the gateway into your site, would help you, but that's not what programming help is. programming help means you are doing 99% of the work and we are just providing direction. in order to provide you with any direction, you must be at the point of asking specific questions or have specific errors or symptoms that you need help with. short-answer: you want something, you don't have the knowledge, skills, or experience to do the work yourself. that is the test for when you should hire someone to do the work for you, especially if the task involves actual money and products. re: your drawing example. i recall some lady making an attempt at touching up an expensive painting within the past year, and it came out looking like a kindergartner did it with finger paints. the work required someone with the correct knowledge and experience, not just someone with a brush and some paint. -
Is there anyone could solve my math problem
mac_gyver replied to infosounds's topic in PHP Coding Help
scientific notation is just another way of representing a floating point value. to get the output formatted the way you want - $answer = sprintf('%.11F',1/212500); @Richard_Grant, the large image in your signature is in violation of the forum's rules. i suggest you remove it or make it much smaller before you receive warning for it. -
in your previous thread, it was suggested to use mysqli_error($con) to display query errors. what worked before, can work again. you would be getting a query error at or right after the $tablename portion of the query because you are using a non-existent $_POST variable to provide the value for the $tablename variable. you would also be getting a php undefined index error where you referenced that non-existent $_POST variable.
-
Using .htaccess for auto_including files in framework
mac_gyver replied to deathbeam's topic in Application Design
also, putting php settings into a .htaccess file only works when php is running as an apache module, which is uncommon on shared web hosting. so doing it the way you are trying would limit your framework to just apache servers and to just a fraction of those that have php running as a server module. -
PHP form moved to new server, all kinds of weird issues
mac_gyver replied to rjo98's topic in PHP Coding Help
a) change the short-opening php tag <? to a full <?php tag. the short one is not portable between server settings and was a waste of time just to save typing three characters. b) ALL of the program variables, based on form data or server data, don't exist. you will instead need to use the $_POST and $_SERVER variables to access them. setting php's error_reporting to E_ALL and display_errors to ON will help you find these since they will all produce undefined variable error messages. c) if you review the php.net documentation appendixes, there are migration sections that describe what has changed over time in php. -
in actuality, once you have the necessary database tables set up, the only thing you need to do differently in any cart code to accomplish what i suggested is to change the queries that operate on the data. the following is a little different from what i described above (which is why you should work out the details yourself, rather than follow along with what someone quickly writes out in a post somewhere on the web.) instead of having a query that updates a row to subtract the quantity in your products table, you would instead insert a new row into a different table (such as a cart/order_details table), with the item id and the quantity that was ordered (if you store the cart in a database table, instead of a session, this step isn't needed since the item id/quantity would already be in a database table.) any query that needs to get the current quantity, instead of reading the row(s) from your products table, would take the quantity on hand and subtract the SUM() of the quantity from this new table. if you do an advanced search on the forum for 'cart' and my user name, you should find a lot previously written information about this. in fact, see the second half of the post at the following link -- http://forums.phpfreaks.com/topic/286051-php-shopping-cart-and-quantity-help/?hl=%2Bcart&do=findComment&comment=1468275 and i added the forum's bbcode tags around your posted code above, as that may have been a reason no one bothered to look at the code to offer any specific help with it.
-
prepared queries aren't just about security. $variable = "Mc'Gyver"; results in broken sql syntax and an error.
-
the main point of using a prepared query is to bind data into the syntax of the query. the syntax of the query, less the data, is what is being prepared. the data values are actually supplied and inserted when the query is ran, so that there's no possibility of sql injection. by putting a variable holding raw data into the sql query statement, you have side-stepped the process, and allowed sql injection. @deathbeam, putting a variable directly into the query being prepared, in itself, doesn't cause any type of error. in the php context, the sql statement is only a php string that is being built.
-
sorry for this, but we are not here to find or to give you things you need or want, because we don't know the requirements of your assignment or what your skill level is. that's NOT a suggestion to post your requirements. the only person here who can find what you are looking for is you. we can help you with specific questions you have once you have attempted to do this and have actual code and symptoms or errors you can post or if you have a specific question about how to do some part, again after you have attempted to figure it out first.
-
the code is doing exactly what it was written to do. if you want it to produce different specific data, you will have to write the query and code that does what you want. if you want to graph one bar for each/any month, with the total for that month, you will have to produce data that does that. [month name,total for that month],[another month name, total for that month], ... you should do this in the query, like the example that Psycho posted (modified for a total and $type you are actually doing), which if you are going to do this in general for any range of dates, would be the best place. to get the month name, you would either convert the 9 to the name in your php code or you can use the mysql MONTHNAME() function in the query. edit: in addition to what others have mentioned, i recommend that you use table alias names in your query to reduce the clutter and make it easier to read and easier to write in the first place.
-
just because an update query runs without any errors, doesn't mean that it actually updated the row, if the WHERE clause if false. you should also be testing if the number of rows updated is greater then zero. to debug the problem of why the update query isn't updating the data, have you echoed the $query variable so that you know it contains what you expect?
-
see the sticky/pinned post for this forum - http://forums.phpfreaks.com/topic/150979-this-board-is-not-a-code-repository/ php help forums are not for finding or giving you code that you want or need. we are here for helping with actual code problems. topic locked.
-
Program PHP to produce HTML output using tables to render results.
mac_gyver replied to Halebutt's topic in PHP Coding Help
you are also going to need to ask specific question(s). just posting a list of requirements, isn't asking a question, but it is a fine start at a request for quote to hire and pay someone to do this for you. we are here to answer specific questions that you have, after you have made an attempt at solving your programming problem. -
one of the most likely reasons for session variables not working when redirecting all over the place is that the redirects are switching back and forth between having and not having the www. on the url, because by default, a session will only match the variation of the url where it was set.
-
given that you are using the DISTINCT keyword, i doubt there are exact duplicate rows. i suspect you mean that the job information exists in each set of rows for any job_id. if that's the case, that's how joined queries work. if that's not the case, you would need to post the result you are getting. however, that query is not what was suggested. you either need to separate queries, one for jobs and messages and the second for jobs and quotes OR if as has already been stated, if the columns you are selecting for messages and quotes are similar in meaning (because the UNION query will use the column names from the first query in the UNION), you can write one query that combines these two queries as a UNION query.
-
the short answer is to treat your inventory as a deposit/debit account, where you have a row for each transaction. each row contains all the who, what, when, where, and why information about the transaction. when inventory is added (including the initial quantity), you insert a row with a positive quantity (deposit). when inventory is added to a 'cart' and the person go to the checkout stage, you would you add a row to the database table for each item in the cart, listing a negative quantity (debit), but with a status value that indicates is has been 'ordered'. when the item is actually pulled and shipped, the status for each item would be changed to 'shipped'. to get the current quantity of any item(s), you would simply run a query that sums up the positive and negative quantities for each item id/item number.
-
@Richard_Grant, is_int and is_string test the type of a variable, not what's in a variable, and by definition all $_POST data are string variables, no matter what's in them.
-
posting a sql dump of just your table definition, would help someone to recreate/debug the problem.
-
it's likely that your new-lines in the csv file doesn't match $lineseparator = "\n"; where/how is the csv being produced and are you editing it at any point, where your editor could be modifying the new-lines?
-
have you ever successfully sent an email from the server where this is running? does your web host have any smtp authentication or other requirements to send email? there may be a mail server that accepted the email from the php mail() function and didn't return an error to php, but that mail server may not have any intention, or ability, of actually sending the email to the recipient or it may not even be the correct mail server to use at your web hosting. it's also possible that the dns records where the domain in your From: address is hosted at are either nonexistent or miss-configured such that the receiving mail server cannot determine if the sending mail server is authorized to send the email, in which case the receiving mail server may simply discard the email. is the From: address an actual working mail box, so that any bounce/error messages from the receiving mail server would have a place to go and can be viewed? and while the From: address should get used as the Return-path: address for bounce messages, you can specifically include a Return-path: in the header. edit: also, which email address are you not receiving at, the To: address that you are entering in the form (and have you confirmed that the form is posting a value to the code), or the Bcc: address that's in your code or both?
-
Inserting array data into multiple rows of database
mac_gyver replied to mythri's topic in PHP Coding Help
that's not correct jazzman. the posted code is escaping/casting each data value as it is building the string being put into each array element. each array element is one complete value section of the query - (1, 'a string', 2.34) (with the surrounding ()). the implode is just combining all the array elements into the VALUES section of a multi-value insert query. any escaped data in the array elements will still be escaped in the resulting sql statement. you cannot escape any of that afterwards since that would change the quotes that are part of the sql syntax. if there was a string data value - this contains a ' in it, the posted code will produce - (1, 'this contains a \' in it' ,2.34) your suggestion to apply the escape function after or as part of the implode would produce - (1, \'this contains a \' in it\', 2.34), which is not correct. the posted code produces the following actual sql query statement for some test data - INSERT INTO order_line_items (order_id, company_id, item, unit, unit_cost, quantity, tax, total) VALUES (0, 0, '123', 'this contains a \' in it', 0.00, 1, 1.00, 2.22), (0, 0, '456', 'this contains a \' in it', 0.00, 2, 2.00, 4.44) the only problem with the posted code, outside of any typo's, may be that the $item value is likely an id, not a string.