Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by gizmola

  1. Not understanding -- sure that is an issue for many people. I will grant you that there is a learning curve, and for many people the big picture is difficult. With that said, most of these projects had great documentation, and tutorials and demo projects to help people learn them. Writing everything from scratch was a mistake, because your site should have implemented MVC to give it a sane and maintainable structure, and you also clearly wrote lots of code that doesn't have a set of robust unit tests, so your site is inherently more buggy and less stable than it would have been if you had used a framework. You also reinvented the wheel, big time, rather than concentrating on the important things, as in your business logic ,and the functionality of your site. To rationalize this decision as a "challenge" when that challenge did not even include learning the basics of PHP OOP -- is It is what it is, but the path to becoming a better developer is being able to admit you made a mistake. Most project teams include a post mortem for this exact reason -- to reflect on the process, evaluate what worked and what didn't and hopefully improve.
  2. Pretty full article on using the various Geometry and Geospatial features of MySQL and it includes manual references. Using the Postgis extension with Postgres. It's also worth looking at MongoDB which has pretty much had a GeoJSON type since it's initial release, as well as indexing to support it.
  3. This is not the problem you seem to think it is. Really the only really insurmountable problems that can't be fixed with media queries, would be if you are styling predominately through the use of inline style statements echo'd in your php code, or if you have the entire site layout in multiple nested html tables, as was the case for many a site in the olden days. Something as trivial as a margin/padding etc. is not a problem at all. You do a media query and simply change the things that are not mobile friendly. For example: @media only screen and (min-width: 320px) and (max-width: 480px) { .logo img { width: 60px; } .company-name { margin: 0; padding: 0; font-family: Helvetica,Arial,sans-serif; font-size: 25px; } .company-pictures { display: none; } } Simple examples of common things you might do for mobile (use a smaller or different image for a logo, redefine a style class you apply to certain elements, completely hide a block that is nice to have but not essential for mobile users). For the record, 8 years ago there were a lot of things available that you could have used to build your site with. MVC frameworks like Zend Framework (2006), CakePHP (2005) and CodeIgniter (2006). Symfony 1 was released in 2007. Symfony2 was released in 2011. Not long after that, composer was released. Laravel was released in June of 2011. I have made efforts to make you aware of some of these projects in the past. Fear of breaking things you manually tested should not be an excuse not to change code, either permanently or experimentally. Is your code in a git repo? Have you pushed this to a private repo under github or bitbucket? If not, why not? If so--- Here's what you do: Make a branch (git checkout -b css-test Change as much or as little code as you want to experiment Commit your changes (Optionally) push your branch to your repo [while in branch] git push -u origin css-test If it goes to hell, no big deal, you made a branch and you can delete it if you want. If things work out, you merge your branch to master.
  4. Adding onto Barand's reply, here's the technique to ingest the original integer and turn it into an array of digits. function mul(int $int) { return array_product(str_split($int)); } echo mul(12345); // 120
  5. I think the point you are making, is that there is no holistic cross language debugging tool, but then again that is the nature of web development. There are a lot of different languages and ways you can connect things, which require different debugging tools. In recent years most of my projects have been done with either Symfony or Laravel, and they both offer a debugging toolbar that tries to bridge the gap somewhat, but at the end of the day, I find there are a number of different tools and techniques you need for debugging. The same is probably true of any networked system, where there are a variety of services that are connected in a non-trivial way. From a front end standpoint, the more complicated the javascript, the more you need to use the developer tools. More often than not, I'm looking at the network tab and looking at the request/response data. I'm typically only using the javascript debugger when I have something specific that I know is broken in a particular way. If I'm not sure exactly where thing are going wrong, then I'll step through the code by placing a breakpoint at an early/well known point. At the end of the day, once code is running in the browser, it is no longer something you can debug from the serverside.
  6. PHP is a very different language from the one you learned many years ago. Any code you might have written is entirely obsolete, and probably you are running a PHP version that long ago was end of life. Candidly, PHP wasn't looking pretty viable, but in the last decade it has been steadily improved to once again be one of the best languages for web development. It has an excellent dependency manager: Composer. This enabled the creation of a truly impressive array of component libraries, many of which have great code coverage and unit tests, insuring quality and stability. It has two state of the art Dependency Injection frameworks: Symfony and Laravel, and there are others that are capable. There are several ORM's for relational database development supporting both the Data Mapper pattern or Active Record. The language has been enhanced to support many of the constructs and type of coding available in other languages, and performance has been improved in a variety of ways, so that large commercial websites are comfortable using it. It's once again a great time to be a PHP developer, but it's also a time to update your application and your knowledge. I would highly recommend learning either Symfony 5.2 or Laravel, by porting your application to them. In the process you will update your skills and at the same time, have a website that is clean, secure, maintainable and with your code concentrated on functionality rather than the basic MVC code most websites utilize.
  7. Javascript debugging is done in the browser using the built-in developer tools. People typically use chrome. The exception would be if you have a node application or javascript front end application built on vue or react etc. but in that case you are going to have the front end code separate from the back end code, and be implementing a REST api or something similar on your backend, which is basically what you would want to do for any ajax calls. If you have lots of mixed PHP/HTML scripts you can still debug those with the PHP debugger, but it's really not a great way to develop clean maintainable code. Most pro developers use PHPStorm. It's not free obviously, but it's the premier solution. It has so many options it can actually be pretty daunting, but it also provides the best navigation through a complicated code base of any IDE. As for free options, I have also used phpeclipse, which is built on top of eclipse. It's not terrible, as Zend for a time had a commercial product based on it, but Zend no longer exists as a company. Lately I'm using Visual Studio Code, but I haven't made a lot of efforts to get it setup for PHP. It's really where a lot of the web development community has migrated, and the support and velocity of enhancements is very high.
  8. It looks to me like you have some sort of sync issue with your environment, because there is no reference to a key of 'title' in the script you posted. There could be all sorts of reasons depending on how you are testing or revising your code. This could also be because you have a cached version of your code. Did you try to restart your apache/php? If that doesn't fix the issue, I'm not sure what to tell you, as the code you provided does not include 'title', but does include 'titel' in a number of places. If you changed the spelling of 'title' to 'titel' recently that would also suggest a caching issue. If you are interested in where this type of caching might exist in a development environment, reference OPCache. OPCache is a performance enhancement that caches source code in memory to vastly improve runtime production. It might be installed in your xampp. In a development scenario, it is probably advisable to disable it just to remove the possibility it might interfere with your development cycle. Again this is just an educated guess based on what you provided.
  9. You also have to realize that there are no longer any versions of PHP that will work with unaltered 10 year old code. You most likely will need to update your system to work with a current supported version of PHP.
  10. There isn't really a "php database". PHP can talk to many different types of databases through client libraries. So... I can not guarantee this is going to work, but it's worth looking into. The primary goal here is to keep you within PHP which you know, which should make writing the code you need within your comfort zone. You need an MQTT Broker that your ESP32 device will be publishing to. This needs to be some sort of network connected device that can run your MQTT broker, as well as your SQL database + storage for your data. You will also be running an MQTT client job that will be subscribed to the broker and will take data and add it to the SQL database in (near) realtime Here is an async server package called Swole that is added to PHP via an extension. You would need to use PECL to add it to your PHP installation which will live on the aforementioned server With Swole you run a php based MQTT broker/server. Here's simple code that shows how you would do it: https://www.swoole.co.uk/docs/modules/swoole-mqtt-server You write a client who subscribes to your MQTT Topic for the data you are charting, and transforms that data. Again there is a php library for this, and there may be others if you do some googling, packagist searches etc: https://github.com/php-mqtt/client Your client will receive the data and add it to your SQL database each time a relevant message is received with data you want to store Now theoretically, you can cut out this client piece by adding code to your Swole based MQTT broker. As messages are published to the topic, you should be able to process the data and add it directly to the the sql database, so like anything there are multiple different ways to do this with strengths and weaknesses for each. If the server code can do it directly, clearly that's simpler and better.
  11. Another way of doing this that uses some array functions would be: $countries = array_intersect_key($countries, array_fill_keys(array('US','CA'),0));
  12. Highly unlikely. Performance tuning isn't something that is typically fixed with a couple lines of code, and typically requires various forms of expert level profiling and sysadmin/devops skills.
  13. Yes, well we would need to actually see your code if you want help.
  14. Good luck with your studies.
  15. I missed the subtlety in your question. Barand has a good solution.
  16. Here is a simple example, turning the date strings into DateTimes and then using format to output the date. You will need to read the manual page Strider64 provided to reference all the different ways you can specify output. There are also a number of predefined constants you can use. <?php $dates = array('2005-05-21', '2006-11-01', '2006-11-02', '2020-09-28', '2020-09-29', '2020-09-30', '2020-10-01'); foreach ($dates as $date) { $dt = DateTime::createFromFormat('Y-m-d', $date); echo $dt->format('r'); echo PHP_EOL; echo $dt->format('\i\t \i\s \t\h\e jS \d\a\y.'); echo PHP_EOL; echo $dt->format(DateTimeInterface::ATOM); echo PHP_EOL; echo PHP_EOL; } Your dates all need to be valid, or you may get some odd results. It is possible to check as to whether or not a date was invalid, which is documented on the manual page for Datetime::createFromFormat(), if that is a possibility you need to handle.
  17. So you have 2 items you can work on. The first was brought up by benanamen, which is really a syntax issue. You are not referencing arrays correctly: // Use this if (isset($_POST['itemName']) { // Not this if (isset($_POST{'itemName'}) { That is not the source of your current problem however. Your current problem is that whatever javascript you have that you assume is making your form valid, is not valid, so your text field is not being passed when the form is posted. Another good debugging tool is to use something like chrome dev tools, and look at the network tab when you submit the form. You can then see the contents of the post variables as they are sent when you submit the form. In conclusion, right now your problem is your html/javascript code and has nothing to do with PHP. The code is working as you intended, as $_POST['itemName'] is not set/does not exist.
  18. Add a debugging statement at the top of your script of var_dump($_POST) and verify your assumptions.
  19. I will try and come back and take a look at your code, but I wanted to say that using PDO is great. I would say that the staff is universally in favor of using PDO, so no worries about learning mysqli.
  20. Transactions are another one. I don't really disagree with what you wrote, and in fact I linked to information that agrees with you. The problem with anything concrete is that we don't know if jodunno is using PDO or MySqli.
  21. Actually, I think that Barand just made a small mistake, which is certainly very unusual for him The unique constraint should be: UNIQUE KEY `unq_page_link` (`user_id`, `page_link`), That will enforce uniqueness on a user/link basis, which is what I assume you are going for. This is a better solution in that you are using the db to enforce your integrity rule rather than relying on the front end code to do it for you. With that said, code around database queries needs to be written in a way that you catch and deal with database errors appropriately. Typically that is done with a try..catch block. I can't give you specifics without knowing in advance what db api you are using (mysqli vs pdo) . Here's an example out of the "(The only proper) PDO tutorial" which is highly recommended reading for anyone learning the PDO api: try { $pdo->prepare("INSERT INTO users VALUES (NULL,?,?,?,?)")->execute($data); } catch (PDOException $e) { $existingkey = "Integrity constraint violation: 1062 Duplicate entry"; if (strpos($e->getMessage(), $existingkey) !== FALSE) { // Take some action if there is a key constraint violation, i.e. duplicate name } else { throw $e; } } Assuming you are using PDO this could be adjusted to fit your problem as it is essentially the same issue you would face in dealing with the unique constraint violation to prevent a user from adding the same link multiple times. If you are using mysqli, then you should certainly read this. A general discussion of php error handling strategies is good to read. The important thing to note about this, is that you don't want to generalize error handling to try .. catch blocks around all your queries. This is a specific issue, having to do with something you expect to happen frequently. Lots of other database exceptions can happen, and you want to have a generalized exception handling solution for those.
  22. The html generated along with the css you used, would allow people to help you diagnose what is or isn't working. Also, you would still need tables, or alternatively convert to flexbox or css grid
  23. Please provide an example of the array you are expecting to generate.
  24. Let's look at your method: public function countVehicles (){ $this->db->query("SELECT COUNT(id) FROM vehicles WHERE id = :id"); // Where is the :id parameter? You do not pass it into the method nor do you pass it to the query $counter = $this->db->rowCount(); // This, should it work, will always return 1. Not what you want! return $counter; } You do not want to do a rowcount on that query, because it will always be 1. Select count(id) is going to always return one row. Even if there is 1 row counted or a million, or zero. The reason the query was suggested is that it will always have a value. With that said, you would need to fetch the row to access the value, not count the number of rows in the result set. Personally, in order to have a simple column name to use, I will alias the result of a count() query like the one suggested. Here is how I would do it: "SELECT COUNT(*) as count_of FROM vehicles" Then if you have fetched this result into a variable in some way, you can expect to access the value via something like $row['count_of']. With that said, your query by id, assuming that id is the primary key of the vehicles table, will always count at most one row, because the primary key must be unique. There are compound keys that could complicate this, but I don't see anything you are doing that suggests you have a table with a compound key. Are you just trying to get this to work, so that you can do what you *really* want to do? I'm going to assume you actually want the count of all vehicles as you did initially. If things were working as they should, your original code should have worked. Something is not working in your database model/class. Unfortunately, I can render no further aid, because I would need to know more about what "MVC" you are using. MVC is a design pattern, not an implementation, and has been implemented in various ways by nearly every popular PHP framework, with a few exceptions. What framework are you using, or is this something you have built yourself from scratch? What is the source of the database class?
  • 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.