-
Posts
5,450 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
and the multi-value update can be implemented as the following without having to dynamically produce case logic in the query (assuming that id is a unique index) - INSERT INTO tablename (id,col2) VALUES (1,'AAA'),(2,'BBB'),(3,'CCC') ON DUPLICATE KEY UPDATE col2=VALUES(col2)
-
How to get part of xml faster using XMLReader?
mac_gyver replied to DocNet's topic in PHP Coding Help
you shouldn't be trying to put any search/filter functionality into the low level interface/driver. the purpose of that code is to serve as an interface between the application and the api. that's all it should do. it's your application code that knows what the data means and is where any data processing belongs. xpath is used to select nodes from an XML document. you don't need to find the nodes containing the data, you already have them. for bulk data processing, looking for each individual data record in the xml is not efficient. just loop over the bulk xml data and determine for each record if you need to insert a new database row for it (it doesn't exist at all) or update/replace the values in an existing database row. -
Change image on website based on time in day
mac_gyver replied to krishh33's topic in PHP Coding Help
for a php produced page, your code should be laid out in this general order - initialization, post method form processing, get method processing, and html page/template. (see the following post for more information about these items - http://forums.phpfreaks.com/topic/296602-storing-multipe-session-variables-for-a-cart/?hl=%2Binitialization&do=findComment&comment=1513104 ) the defined constants, $path, and $a[] statements from the code in this thread are configuration information. they would typically be in a config.php file that you include in the initialization section on the page. the $hm, $d and the foreach(){} loop are part of the get method processing code, they produce data, the $img value, to be used in the html page/template section. the final if(){{}else{} statement that displays a message or outputs the <img ...> tag goes in the html page/template section, at the point where you want to display the image. the html page/template section starts with the <!DOCTYPE tag through to the </html> tag. -
How to get part of xml faster using XMLReader?
mac_gyver replied to DocNet's topic in PHP Coding Help
here's the likely problem that's causing the else {} block of code to take (much) longer than the initial storing of the data in the if(){} block of code. you are storing multiple rows for each FixtureMatch_Id, one for each bookmaker and, i would guess, type combination. so, for any FixtureMatch_Id, you have 20+ rows. when you are updating the information, in the else {} block, your select query is just getting the FixtureMatch_Id and UpdatedDate, and the rows in the result set will be in no particular order. you are getting all the rows from your table, 20+ rows for each FixtureMatch_Id, times the number of different FixtureMatch_Id values. as you are looping over the database rows, you are hitting the XMLSOCCER.COM api for each row. for any particular FixtureMatch_Id value, you are retrieving the same data from the api 20+ times, repeated for each different FixtureMatch_Id value. for what you are doing (as far as i can tell), if you set up the correct unique composite index on your database table, you can use the code in your if(){} block, without the condition around it, with a REPLACE ... query, to INSERT new data and UPDATE/REPLACE existing data. the unique composite index would be over the - fixturematch_id, bookmaker, and type columns. note: this method will REPLACE data in the table that has the same updateddate as the 'new' data, wasting some database processing time. if you want to avoid this extra work on the database side, you would have to select the fixturematch_id, bookmaker, updateddate, and type from the table first, and detect when those four combined values are different from the data being put into the query. the most efficient code for doing this would be to concatenate those four values, with a unique separator character ( a | for example) and store the values in an array. you can then concatenate the data values using that same separator and use an in_array() statement to find if the composite value is already in the database data. if it's not found, run the query. if it is found, don't run the query. lastly, the bindparam() statements don't belong inside the loop. the only thing that goes inside the loop are statements that populate the variables that were bound and the ->execute() statement. edit: if you use an INSERT ... ON DUPLICATE KEY UPDATE ... query, instead of the REPLACE query i mentioned, it may (untested) be more efficient and you won't need to first check if the updateddate has changed, assuming that the UPDATE part of this type of query operates the same as any UPDATE query, which doesn't actually perform the UPDATE (writing the data) if the new data values are the same as the existing data in the record. -
How to get part of xml faster using XMLReader?
mac_gyver replied to DocNet's topic in PHP Coding Help
are you using the XMLSOCCER.COM api's parameters to get just the data you want, for example GetAllOddsByFixtureMatchId, or are you getting all of the data and trying to parse it yourself? -
Bottleneck somewhere not sure if php is causing it
mac_gyver replied to oracle765's topic in PHP Coding Help
no. you have to find what''s causing the problem, before you can fix it. the javascript would apply to the client-side rendering time, which isn't much, compared to the time waiting for the server to send the response. -
Bottleneck somewhere not sure if php is causing it
mac_gyver replied to oracle765's topic in PHP Coding Help
i just checked the http://www.compareandchoose.com.au/adventure_activities page at both http://developers.google.com/speed/pagespeed/insights/ and http://tools.pingdom.com/fpt/ and the large amount of time taken, ~2 seconds, is waiting for the response back from your server, rather than things the browser must do to render the the page. the amount of time is fairly consistent, over about a 5 minute period i checked. you will need to profile what the code is doing in order pin down where it is spending this amount of time. -
Bottleneck somewhere not sure if php is causing it
mac_gyver replied to oracle765's topic in PHP Coding Help
you need to determine the page generation time, by taking the microtime(true) value at the start of the code on a page and again at the end of the code on the page, and calculate the difference. this will tell you if the problem is with the generation of the page or elsewhere, such as in the web server taking a long time to actually invoke php after the http request was received. if it turns out the problem is in the page generation, you need to calculate the time taken at different points in the code, around database activity, around calls to external api's, ... to narrow down where the time is being consumed. -
Login Page won't work, using pHPass
mac_gyver replied to beginnerProgrammer_96's topic in PHP Coding Help
unfortunately, some versions of browsers (IE/Opera for one) have/had this problem. this can also occur when submitting the form via javascript. the submit button isn't a "successful" form field when the the form is submitted by means other than clicking on the submit button and the submit field isn't included in the form data. in those cases where you need to identify which of multiple possible forms was submitted, using a hidden form field or testing for a field name that is always submitted addresses a type = submit field that may not be sent with the form data. also, unfortunately, the OP's code in this thread was using name='login' in the form, but was testing for isset($_POST['submit']) in the php code. -
Login Page won't work, using pHPass
mac_gyver replied to beginnerProgrammer_96's topic in PHP Coding Help
it's not really possible to program by randomly putting things into your code. you must know what each line of code does, so you will know how it contributes to what you are trying to accomplish, know if it even belongs in the program, and know where it belongs in the flow of the program logic. the code you posted in reply #3, was using the CheckPassword() method in the correct logical location and you were including the PasswordHash class definition in the correct logical location, relative to trying to use it. you were however missing the line that created an instance of the PasswordHash class and you were using the wrong php variable as a parameter when you called the CheckPassword() method. everything you changed after that point, from where you added it, to adding a call to the HashPassword() method (hashing the password is done when the password was stored during registration, not when trying to log in) makes it appear that you are not even looking at what you are doing, similar to trying to put together a jig-saw puzzle without looking at the picture on the box and what portion of the picture is on the piece you are trying to find a location for. so, best advice, slow down, actually learn what each statement does, look at and think about what your code is doing at each step, so that you can put in other statements at the correct place so that they will have meaning for what you are doing. -
Login Page won't work, using pHPass
mac_gyver replied to beginnerProgrammer_96's topic in PHP Coding Help
the correct logic to check the password is to call the CheckPassword() method (after you have created an instance of the PasswordHash class in $hash_obj), with the correct values. in your code that had/has this call, the second parameter you are using was/is $stored_hash. however, there is no variable $stored_hash in your code. your code is using $password_hash. beyond this, due to the number of changes you have made to the code, if you cannot get it to work, post your current code. btw - php has built in password hashing functions - password_hash()/password_verify(), that you can/should use instead. -
have you done any debugging to make sure that the $_FILES data is what you expect? also, there are at least three problems with what you are showing use in that code - 1) you should validate that input data exists and is what you expect before using that data. your code should never get to the point of running a query unless you know you should be running that query. 2) isset($_FILES["fileField"]) that $_FILES element will be set, even if there is no valid uploaded file. if a user doesn't select a file and likely for some of the possible upload errors, what you are testing in the isset() statement can be true, but the ['name'] element that you are using can be empty. this is actually related to the above item. you shouldn't be testing for data at the point of using it in a query. by the time you get to the point of forming and running the query, you should have already determined if there's data present. 3) "all other text fields update fine". unless you removed lines of code from what you posted, that implies you are repeating similar code for each field and are running a separate query for each field. that is a database killer. you should update all the fields using one query (note: if none of the values being updated have changed, mysql doesn't actually update the record.)
-
¶ should be &: I don't know what's wrong
mac_gyver replied to peterhuynh's topic in PHP Coding Help
without knowing where and how this is being produced, where and how you are viewing the incorrect value, and what sort of processing might be occurring between those two points, it's impossible to tell. could be due to a programming problem changing the value or copy/pasting part for that value from somewhere that has some character encoding that looked correct where it was copied from, but isn't actually the charters they appeared to be or some type of character encoding issue with the method you are using to view the value. -
since the output, that's causing the problem, is occurring on line 1 of the file and the only php code on that line is the php tag, you either have something in the file before the php tag or your file has been saved with utf-8 encoding and the BOM (Byte Order Mark) characters by your editor. insure that there's no characters before the first php tag and insure that your editor is saving the file without the BOM characters.
-
include file only loads all content on the last time included
mac_gyver replied to flemingmike's topic in PHP Coding Help
this is some confusing code and probably doesn't work because the output being produced is not valid. the markup you are producing, particularly the javascript, is being repeated for each main row you are looping over. you need to separate the concerns/responsibilities in the code. the data retrieval logic should all be together, come before any markup, not contain any html/javascript/css markup, and just store the retrieved data in a php array. the code building the page, starting with the <!DOCTYPE ... tag, should just take the data from the data retrieval logic and loop over it as needed to build the sections/views on the page. the things that only exist ONCE in the markup, such as the jquery javascript <script> ...</script> tags, should not be inside of any loop. next, you should never run database queries inside of loops. the data you are retrieving is related, as in the R in RDBMS. the correct way of retrieving related data is to run one query that JOINs the tables to retrieve all the related information at once. and here's the most confusing part from your code (we only see what you post, so it must clearly tell us the story of what you are doing), you are looping over the result from each of the queries, but i suspect that each query, except for the main one, only matches one row? OR can there be multiple timesheets per workorder, based on what appears to be a variable for totaling the time? you should also be using css instead of inline styling and the msyql_ database functions are obsolete and will be removed from php in the not to distant future. you should be switching to either the msyqli_ or PDO database library of functions (having all your database retrieval logic together, on in your case, where you should only have one query, will make switching to a different set of database functions easier.) in short - run one query that gets the data you want, retrieve and store that data into an array, then, in the code that's producing the page, loop over the data, building the markup needed to display that data. this will reduce all your code, make it easier to debug each concern/responsibility (which makes it easier for us to produce test data if we need to run your code to help with it), and make it clearer to us what you are doing. -
once you get past the query errors (see Barand's reply #5), you are using the page part of pagination incorrectly. the logical page number from the link - 1, 2, 3.... needs to be converted to the offset value for the query statement by subtracting one and multiplying by the rows-per-page/limit value. since the offset value is now a calculated value, it doesn't need to be a bound parameter in the query statement. likewise, if the limit value is defined in your php code, it doesn't need to be a bound parameter.
-
Adapting my Calendar to work across more than 1 Month.
mac_gyver replied to fileparts's topic in PHP Coding Help
you need to use dates with a YYYY-MM-DD format, so that you can do greater-than/less-than comparisons. your dates should be stored in the database using a DATE data type, which will give them that format. this will let you retrieve only the rows that have a start to end date range that matches the year-month you are trying to display. next, just store the retrieved data directly in one php array, with the id, start date, and end date. as you loop over the days in a month to display the calendar, you will form the current date with a YYYY-MM-DD format. for each day, you will then loop over the array of data and retrieve the id(s) where the current date is between the start date and the end date. edit: an alternate method would be to expand the start date to end date into individual dates within the range and for those dates that correspond to the year-month being displayed (dates before and after the current year-month would not need to be stored), store the id as an array element for each day, using the date as the main array key. this would result in an array that looks like - $array['2015-06-01'][] = some_id; // some_id is booked on the 1st and 2nd of this month $array['2015-06-01'][] = someother_id; // someother_id is booked on the 1st of this month $array['2015-06-02'][] = some_id; as you loop over the days in the month, just loop over any sub-array of id's, if present, that have a main array key matching that current date. -
sorry if this is all negative, but the php coding help forum section is for getting help with code you have written. the application related help forum sections all have sticky posts/rules about not posting requests looking for specific applications. the main reason that programming help forums are not good at finding things for you is because we don't know your requirements or your coding skills. the only person who will know if an application meets your needs or if it is simple enough that you will be able to troubleshoot it if it doesn't work, is you. if you have a problem with a php application you have found, that you cannot solve yourself, you either need to ask for help on the author's web site, or you can post in the phpfreaks third party php scripts forum section, but since we are not likely to have specific experience with any particular script (and you won't be able to post copyrighted code anyway), we can only offer general troubleshooting help.
-
Create Search in php and Display results as Products
mac_gyver replied to Adibhise's topic in PHP Coding Help
@ the OP and for all the other current threads where all that is being posted is an urgent list of what you want. a list of what you want is nice start for a RFQ (request for quote) to hire someone to do this for you. it is not however what programming help forums are about. programming help forums are not free programming services. they are also not for getting unpaid research assistants to find things for you. they are for getting help with specific programming questions (how to create an entire application is not a specific question) or getting help with problems and errors in code you have written. the internet was created for publishing and researching information. everything you are currently doing has been done before, countless times. there are literally 10's and 100's of thousands of code examples posted on the internet showing how to use php to dynamically create forms, test for and validate submitted form data, create database connections, insert data into a database, retrieve information from a database, update information in a database, and delete information in a database. if you haven't found code examples that do what you want, you haven't done your part researching the information. -
the other thread about retrieving data based on an input id, is just the first step in the U (update) part of a CRUD assignment. this thread seems to be asking about a part of the same U process, but skipped the first step of retrieving the existing data to populate the form fields. this looks more like the C (create) form was just dumped here without having any code to populate it with existing values.
-
unfortunately, someone in one of the OP's other threads made a suggestion that would have produced a trimmed copy of all the input data at once, and paved the way to processing all the form values as a set, instead of writing out repeated code for each separate input value -
-
this sounds like another current thread, where someone just posted what they want and expected someone to do everything for them, especially since the OP in this thread is copy/pasting this question on multiple help sites. first of all, your question about how to do this task isn't a mysql database question. you may be using a mysql database, but until you have a sql query statement at all, you don't have a mysql database problem. next, processing form data and retrieving and displaying database information is what php was created to do and there are 100's of thousands of examples posted on the web for you to find, examine, and learn the basics from. in short - where exactly are you stuck at when you tried to do this? programming help forums are not here to find, give, or write code for you. without knowing what sort of problem you had when you tried this, the answer could range from a) you need to buy a good php/mysql book and/or take a programming class to z) you have a logic or syntax problem in your code that we could help with if you posted your code and told us what sort of error or symptom you got from that code.
-
sounds like the OP just wants someone to do his or his group's assignment for him/them.
-
until you execute() the query, there's nothing for rowCount() or fetchAll() to use and are likely throwing php errors. also, why are you using a prepared query when the sql statement doesn't contain any input values? did you actually write this code or copy it from somewhere? i ask that because i reviewed two of your older threads that also use PDO statements and you previously got the prepare/execute/rowcount statements in the correct order for a SELECT query. programming requires that you actually learn what each statement does so that you can put them together in a meaningful way each time you use them.