Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,448
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. the following is just the relevant part of your code, cleaned up and organized, that builds and runs the two queries - $tableName="business"; $limit = 10; // number of rows per page // produce the where clause // actual where clause code is an exercise for you to do .... // get count of total matching rows $query = "SELECT COUNT(*) FROM $tableName $where_clause"; list($total_rows) = mysql_fetch_row(mysql_query($query)); // calculate the last page number $lastpage = ceil($total_rows/$limit); // get, condition, and limit the $page number $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; // default to page 1 if($page > $lastpage){ $page = $lastpage; } if($page < 1){ $page = 1; } // calculate the starting row $start = ($page - 1) * $limit; // Get page data $query = "SELECT * FROM $tableName $where_clause LIMIT $start, $limit"; $result = mysql_query($query); // the rest of your code goes here ....
  2. you are still doing too much. there's no need to modify the csv data. fgetcsv will read the original csv data by default.
  3. the mysql_ extension must be depreciated for a time before it is actually removed and it is only officially depreciated starting in php5.5 - https://wiki.php.net/rfc/mysql_deprecation
  4. just use the default fgetcsv parameters. you have specifically used a single-quote as the field enclosure character. your data is using double-quotes (the default) as the field enclosure character.
  5. slightly off topic, but no more so than the form section it is in - what does this thread have to do with the forum section it is in -
  6. as a continuation of the above, using a strictly query method, you would do this using a trigger that is ran after each insert.
  7. there's no reason for you to modify the csv file. any piece of data that contains the comma delimiter will/should be enclosed in quotes and fgetcsv can correctly parse it.
  8. here are some hints - both of your queries from $tableName must have the same WHERE clause in them. build the WHERE clause in a php variable so that you can just put it into both queries (don't repeat yourself - DRY). the reason for not repeating code that is used multiple times is so that it is only defined in one place so that you only have to change it in one place. the WHERE clause that you build should only have search terms that are not empty (what CPD and DavidAM are telling you). if $get_name or $get_location are empty, don't even put the LIKE terms using them into the WHERE clause. your logic may in fact produce a completely empty where clause if you want to allow both $get_name or $get_location to be empty. you only need to escape string data that you put directly into queries. $_GET['page'] isn't used directly in a query, nor is it string data, and there's no point in escaping it. you need to limit the value in $page (greeter than 0 and less then or equal to $lastpage) before you use $page to calculate the $start value so that someone entering bad values cannot produce query errors. your pagination links need to have $_GET['search_name'] and $_GET['search_location'] in them so that the search terms are carried over between pages. the mysql_ database library is not recommend for new code (it will be removed in a future php version.) you need to switch to either the mysqli or PDO database library.
  9. that may be correct, but for anyone here to figure out what all your code is so that the result would be complete and error free, it would take a few hours (a few means 2-3.) if someone on a different forum came up with that $500 figure, that's possible too if they looked at the code (no one here has even downloaded any of your files, because we know you don't intend to pay anywhere near what the work would cost.)
  10. @thara, it is usually best to tell the OP what's wrong with his code, rather than to post "fixed" code that doesn't teach what the problem is or how to troubleshoot what the problem is. the code you posted copy/pasted the same error that the OP has and since you didn't state what you "fixed" in the code you posted, the OP would need to scan through or use a tool to compare what you posted to find LEARN what it is you changed that might have fixed the problem or in this case didn't fix the problem.
  11. while it might be possible to do this in one delete/subquery query after you insert the new row, a straight forward method using php would be to - 1) run a select query that gets a row COUNT(*) and the MIN(id) row id for the foreign id value you just inserted. 2) if the row count is greater than 5 (the row you just inserted made six rows), delete the row who's row id is the minimum row id from step #1.
  12. you have a copy/paste typo error on line 31.
  13. what error are you having? nothing in your post indicates exactly what is wrong with the result you got v.s. what you expect. the only things I can tell from what you posted is you are repeating the join condition being used in the ON term a second time in the WHERE term, which is just redundant and unnecessary. you are also use a *_fetch_array() statement in your php code and getting both the associative and numerical indexes. since you probably only want the associative indexes, use a *_fetch_assoc() statement.
  14. the reason you haven't gotten any replies is because all you have posted is a statement of what you want and all the code making up your application. you haven't made an attempt at changing the code do what you want, so you don't have a programming problem yet. wanting to change what your code does isn't a programming problem, it's a want. things you want are obtained by doing the work yourself or by paying someone to do the work for you. either attempt to change the code yourself and then post just the relevant code you need help with or post in the freelancing forum section (and since it's probably going to take a few hours of a programmer's time, you should expect to pay at least a few hundred dollars for the work.)
  15. you do realize that if you don't show us the result you did get and tell us what is wrong with it (what result you did expect), that we cannot possibly help you.
  16. this is a very common activity/task/assignment. there are 100's of thousands of examples posted on the Internet to find and examine to see how others have done this. where exactly are you stuck at in your attempt do do this?
  17. you can store your data on your server any way you want. it does not matter what format it is received/retrieved as. you store it so that it makes sense for how you are going to use it and trying to efficiently search for properties by it's name, rating, birthday, or value requires that each of those values be stored in separate columns (unless of course your assignment is to show that you can come up with the query necessary to solve this, in which case you should be attempting to do this yourself rather than asking on a help forum.)
  18. php is a server side scripting language. you need - 1) a web server 2) php installed and functioning on that web server 3) you browse to the URL of the php script on a web server, not to the php file itself. for a localhost'ed web server, the URL would be http://localhost/install.php
  19. array_search() cannot find the string '158' in values that are like - "157+0", "155+1" you must either use a more advanced search or get your data into a form that you can find the key values. since you are going have to wasted a bunch of time trying to get this to work, just trash this cart and get/write one that stores the cart in an array like i already suggested.
  20. the code you posted for putting the dot in front of the domain parameter was shown for a session_set_cookie_params() statement. did you do the same for the set_cookie() statement? and, if this problem is because of url's having/not having the hostname in front of the domain name, you should be - A) consistent in your coding throughout your site B) have a redirect in your .htaccess file to send all requests to one hostname variation of your domain name.
  21. your array_search() for just the key value will never find anything in exploded $cart_check . to find a key '158', you would need to use a wild card/preg_match type of search because the values at that point are '158+x' to manipulate this cart, take the incoming $cart_check = '123+0,145+1,134+2,'; string and convert it to an array ($cart[123] = 0; $cart[145] = 1; ...) like i suggested. then you can find any key/quantity in it.
  22. your cart data definition is very problematic and is resulting in far too much code for any action on the cart. just use an array, where the array index is the id and the value is the quantity, especially since your code is making an array out of the cart every time you reference it. just eliminate all that conversion code and store the cart as an array in the first place. once you have the cart in the form of an array (your existing code or my suggested way of storing it), you need to use array functions to test and access the data. count() would tell you how may elements are in the array. empty() would tell you if the array is empty. your error implies that there are not two elements in the array (index values start at 0, not 1) and you are trying to access the second one.
  23. if Class::method(0); returns an instance of some result class, which it should so that you can have more than one of them at any time, then using $result->methodFromAnotherClass(); should work. However, since you didn't post the error you got that would have given us actual information about why it didn't work, you are pretty much on you own with that problem. if your question is instead how would you convert $result->methodFromAnotherClass() to a static call, that all depends on what the code is doing. you may need to completely rewrite it to allow for multiple sets of stored properties to support multiple instances of it. in general, using static methods/properties should be avoided, not embraced.
  24. cannot help you with parts of the relevant code you didn't put in your post and spelling errors are not really programming problems anyway.
  25. you need a leading dot . on the domain value to match all hostnames/subdomains.
×
×
  • 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.