Jump to content

gizmola

Administrators
  • Content Count

    4,839
  • Joined

  • Last visited

  • Days Won

    40

Everything posted by gizmola

  1. gizmola

    Creating Google Charts with dynamic data

    So you need to start verifying what has actually worked. For example, var_dump($result) in the php script and see what is being returned. Tools like Postman are good for testing this type of thing if you can't figure out how to do it manually. You need to follow each step and assumption until you determine what isn't working the way you expect. On the javascript side of course do things like use the debugger or even simple alert() statements. One thing I didn't see in your fetch PHP script is you using header() to set the mimetype to be json since that is what you are trying to return.
  2. You need to load the autoloader before you do anything else. It's not optional. The autoloader figures out where your component libraries are and resolves them for you. It should be the first thing you do in your script.
  3. gizmola

    Creating Google Charts with dynamic data

    Are you looking at the console in the Chrome developer tools for javascript errors? How about the server logs for php errors?
  4. gizmola

    Order of dependency injection

    Agree strongly with the advice given previously. There is almost always a way to design an interface once you think deeply about the general purpose of the task. The internal specifics of each protocol just need to be hidden in the injected class(es), which is very much the point of Dependency Injection.
  5. gizmola

    capturing screenshots with Gparted

    I think you may be confused by the documentation. There is nothing in Gparted about it taking screen shots. Those screen shots were added to the documentation to illustrate the UI.
  6. gizmola

    John from Manitoba, Canada

    Hi Slipscream, The journey into development often begins with a story like yours. There is no greater motivation for learning something than wanting to scratch your own itch. Web development is a complicated multi-faceted pursuit that challenges veteran developers in its complexity and scope. When you have questions, we are here.
  7. Nik, This forum has excellent support for code snippets. Just use the <> in the editor, for future reference.
  8. gizmola

    create mp4 with screen recording

    AVI's and MPEG are completely different, so no.
  9. gizmola

    Converting collection of objects to JSON

    Well, no I don't think that RDBMS's support subtypes, although you can model something involving multiple tables that sorta supports it. I have certainly done this in the past, however, my reason had more to do with wanting to write generic code than it did traditional OOP. For example, I had a model with an entity table that was essentially the base of a class. Entities could be these types: member, channel, vendor, stream. So looking at that, it's not very oop, but relationally it had some major advantages. For example, I required a lot of sophisticated grouping. I had groups that for example, defined for a Member their channels. For a particular channel there could be any number of streams. And for each channel there were groups of admins, moderators, etc. Because I had built this around a base entity table, as soon as I had put in place the grouping tables, and written code to support these things, I already had essentially created what I needed to relate these different types of things together whether that be as members to channels, or channels to streams, or vendors to channels. Then there were assets that could be attached to these things, and again, with a generic set of tables that allowed relation of an asset to an entity, it didn't matter if it was a photo in a stream, or a cover image for a channel, or a video for a product sold by a vendor. Once i created comments and tags, I could comment on or tag anything with tremendous reuse of code and DRY. As for serializer, there are several things it does that are sophisticated, and fit Doctrine really well. First it goes through a complicated object tree and figure out how to turn that into a sensible data structure. There is also support for annotating a model to include/exclude particular attributes in your model. For example, you might not want a rest api to disclose internal key values, and with Serializer, you can annotate your model and serializer will automagically support that for you. Your error was simple, and right off the documentation page really... $output = $serializer->serialize($someEntity, 'json'); echo $output; Of course, if you're just testing this, you want to set the content-type of the page: header('Content-Type: application/json');
  10. gizmola

    Converting collection of objects to JSON

    ORM's are ORM's -- they can be great if you drink the coolaid and accept their limitations and quirks. I do have to say that I far prefer Doctrine2's Data Mapper pattern to Active Record which is used by most of the other framework ORM's and with Ruby on Rails for example. This is a decent article that touches upon how the Data Mapper pattern is different (and better in my opinion) than Active Record. In general Doctrine2 is more sophisticated and attempts to do much more than the other PHP ORM's. Some of the things you have been attempting to do that involve inheritance aren't even remotely possible in other ORM's without you essentially hacking them. However, relational databases don't provide or support inheritance of any sort, so you are inevitably trying to force a round peg into a square hole. Probably a decade ago "Object databases" were the hot buzzword, and yet it says a lot that none of the many companies and products emerged with anything that gained a critical mass outside of niche applications tightly bound to specific oop languages. Meanwhile RDMBS's continue to dominate persistent data storage.
  11. gizmola

    Converting collection of objects to JSON

    I am going to guess that you are doing this in order to provide a REST api? Having done this a number of times in the not too distant past, I wired this sort of logic into the controller class. If you subscribe to MVC, which is easy enough to do this via adoption of the symfony framework, then it's fairly easy to create a base controller class that inherits from the Symfony controller class, and into this you can build in things that make your REST api easy to deal with. I mention symfony because you were already using Doctrine if I'm not mistaken, and Symfony already defaults to use of Doctrine. Once you go down this path, then you have the JMS Serializer bundle which handles serialization of complicated object trees into either of json or xml. Even if you don't use symfony, you can still use the Serializer library by itself.
  12. gizmola

    tutorial suggestion

    Does your extensions table have a primary key? It would be best to use that to find the row(s) you need to update.
  13. One of my goto linux commands: df -h Gives you the high level filesystem storage availability. du -Sh | sort -rh | head -50 Gives you a report of filesystem use, largest files and directories listed first. The '-50' at the end controls the number of listings. Tweak that as you want/need. Should help you get an idea of where your storage has gone to and what you might be able to delete to clear space.
  14. gizmola

    Accessing Array Variable

    Json has become ubiquitous in the web development world for a few reasons. When developers started to make heavy use of javascript in order to provide an interactive experience in their web pages, and as Ajax became a prevalent way of supporting interactivity, Json became the preferred way of getting data into javascript heavy apps. Since json is easily converted into javascript objects, this is a lot better than having a server return html or csv or text which then has to be parsed and loaded into javascript objects. Json helped cut out the intermediary steps and required code to either convert javascript objects and data into some other standard before sending it, and provided the same benefit when data was sent in response. As REST Api's became the preferred way of accessing services, more and more of these services defaulted to JSON rather than using the verbose alternative of XML. JSON consumes less network data than JSON, and is certainly simpler to use than xml. Obviously for PHP, json is not a native data type, so you have json_decode() to transform json either into PHP object(s) or PHP arrays() depending on the optional 2nd parameter. It defaults to objects, but often PHP arrays are far simpler to work with given PHP's multitude of array manipulation functions. Conversely, when you need to return json data, json_encode() takes your PHP arrays or objects and turns them into json. Hope this give you some historic context and clarifies a few things.
  15. Did you take a look at this page? https://lastpass.com/support.php?cmd=showfaq&amp;id=6766
  16. gizmola

    Dues Management System

    I would look at the options listed here: https://blog.capterra.com/top-7-free-open-source-membership-management-software-products/
  17. gizmola

    HTTP to HTTPS except for ONE PAGE

    Apache 2.4 allows for conditional blocks. My guess is that it would be far more efficient not to even turn on rewrites when you know you don't need them, not to mention cleaner than muddying up your existing rules with something that you might only need for a period of time. <If "%{REQUEST_URI} != /api.php"> RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\.example.com\.com$ RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301] </If>
  18. gizmola

    subtract a month from a date()

    Strongly agree with Barand on this. I blogged about this topic a mere 14 years ago, but you might find it to a helpful elaboration.
  19. gizmola

    PHP TIME (NOT TIMEDATE) difference

    Given the parameters of your question, I can't think of any meaningful improvement. If I was to quibble with the design of this, your function sec_diff_time() is misleading, because you have baked in the normalization rule. While functionally no different from what you have, I'd try not to compute strtotime over and over simply to do your comparison, given that the result is a unix timestamp integer. Again, just a quibble but there is no benefit in your code to set the constant for seconds in a day to a variable prior to use, since you aren't using it in multiple places. If it's really a constant then this is a case where a PHP define('SECONDS_PER_DAY", 86400) constant is appropriate and wouldn't be wonky in use. function sec_diff_time($s, $e){ if (!validateDate($s, "H:i:s") or !validateDate($e, "H:i:s")) { return false; } else { $startTS = strtotime($s); $endTS = strtotime($e); $endTS = $startTS > $endTS ? $endTS + 86400 : $endTS; return $endTS - $startTS; } }
  20. gizmola

    What PHP should i use? PDO

    In regards to integration of PDO with MySQL, you want to make sure you are using the mysqlnd library.
  21. gizmola

    Adding Column Total

    What you are trying to do is non-trivial and requires an understanding of client side javascript, DOM manipulation and html. Javascript can be a tricky language. Chrome developer tools are vital to understanding and debugging your javascript code. I recommend reading and going through this tutorial and seeing if it doesn't help you with understanding how your current code works, and how to add the things Requinix suggested.
  22. gizmola

    Php runs with ajax in network tab NO errors...

    Try a tool like Postman to debug your script without Ajax client code. Don't use die() unless you want the script to echo immediately. For example, you have $conn->close() at the end, which won't run normally when clearly you want it to. Use bind params for your queries rather than building up your queries into interpolated strings. Doing so is safer, and allows you to remove all the escaping. Your SQL code will also be cleaner and easier to read, maintain and debug.
  23. Integers are the most obvious and performant solution to primary keys in small to mid size systems where you can have a single database. MySQL makes it easy with AUTO_INCREMENT. Make sure that you always define your columns as UNSIGNED so you don't waste half your key space. Assuming MySQL, in most cases the INT type is perfect, using 4 bytes and supporting up to 4,294,967,295 keys. If you have other support tables, you can save space (and increase overall performance) by using tinyint, smallint or mediumint types. The more compact your db the better it will perform over time (assuming proper indexing of required values). You do not need to add indexes for primary key or key columns. Also, make sure you used INNODB for all your tables.
  24. Pretty sure. The only people who would know for a fact are the people who already built the sites you referenced. With that said, as an example of something similar, I was the lead engineer for a project that built a social network application some years ago. It was similar in some ways to instagram, in that users could share streams of media with friends, and was designed to be a mobile application, although it also had a web client. As part of the architecture we accepted music, video and images. The subsystem that handled this accepted most every type of video there is, and then processed and transcoded that to mp4 video at various bitrates. It also extracted a number of different screenshots from the video in order to have cover images in the stream. It also accepted images and sound files. It was essentially a version of what youtube and other streaming video sites do. The primary tool that did the complicated video transcoding was ffmpeg. Because the site backend was written in PHP, I found and enhanced a PHP component library to help with the php integration and make it easier to fit it into our overall backend infrastructure. The library which has been enhanced and added to over the years since is called php-ffmpeg. At the time there were a number of things the library didn't have that I wanted, so I forked it on github and added the things I needed. Primarily it just automated the various command line settings you can send to ffmpeg, and called exec(), but when you're building something that you want to be scalable, there's a lot of work that typically needs to go into making it work beyond the actual generation of transcoded video files. There were queues and organized storage of the files and other things needed so that the individual conversion jobs could run asynchronously and be kept seperate. Without a doubt, ffmpeg was the foundation of the pipeline, but there was also a lot of work put into all the associated requirements that come along with having a business or service, as well as the DevOps work that you need to make sure your system works to an acceptable degree when you have more than one user using it. When people ask about frameworks, my standard answer at this point is to use either Laravel or Symfony. You could certainly use Yii but is not one of the PHP standard bearers at this point. I don't advise people to use Cake or Codeigniter or Zend framework either.
  25. When you GROUP BY you will get one row per group in the result. I like to think of this as compacting all the rows that were part of the group into one row, along with the property that summary/group operators can be used relative to the initial underlying grouping, to compute things like SUM, AVG, COUNT etc. A classic example is a sales table where you GROUP BY YEAR(sales_date) and have SUM(order_total) AS total_sales to get a report of gross sales by year. If I understand your question correctly you want to ORDER the entire result set in a way that is incompatible with the natural property of ORDER by. What you would like is: ALL results ORDER BY campus_name_assignment_table.edited_timestamp DESC Except that once you have a particular campus_id displayed, you want the other campus_name_assignment_table rows for that same campus_id to follow. This can't be done without employing some form of manipulation. The simple solution that uses the ORDER BY, is to order results using your join and ORDER_BY campus_name_assignment_table.campus_id, campus_name_assignement_table.edited_timestamp DESC. This gets you the order of campus_name_assignments to be most recent first for any one campus_id, but it is going to be ordered by campus_id first. Am I right in assuming that this is the problem you are having?
×

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.