Jump to content

gizmola

Administrators
  • Posts

    5,878
  • Joined

  • Last visited

  • Days Won

    139

Everything posted by gizmola

  1. The purpose of phpfreaks is to help people learn about and develop web applications. Ultimately, all we want is people who are genuinely making their best effort. There's no reason for anyone to be angry with you or this thread. I do appreciate you providing an update on your progress, and the reasoning behind your conclusions.
  2. GoDaddy has a bunch of different hosting plans, and lots of servers. Experience with one particular server, doesn't predict exactly what you might experience with a different account, that is likely hosted on a different server. You can get a lot of information just using phpinfo() on each. As Requinix has already discussed, the issue points to lack of the mysqlnd driver. In GoDaddy's cpanel, you can change php configurations using the Select PHP Version. In the menu, I'm guessing you'll see mysqli checked, and nd_mysqli unchecked. There should also be a choice for mysqlnd, that may or may not be checked. If it is not checked, check it. Uncheck the mysqli option, and check the nd_mysqli option. Save this new configuration, and then retry your code. Please let us know if this fixes the issue.
  3. I should add, you could attach this code to the onclick of a button you have separately, or add to every new row. Obviously, as you can see, setting the onclick for the buttons this way makes it very easy to render an equivalent button without having to also manage a call to addEventListener for each new row that's generated. If you only want to have one button for adding new rows, then I'd give that button an id and use element.addEventListener instead.
  4. In this case you don't need ajax. The way to think about a feature like this, is to make sure you are clear on what is happening in the browser when you are on a web page that has already been delivered to your browser in an HTTP response. The page has the DOM loaded, and is running completely disconnected from the server. If you were looking at network traffic, you would likely see that there is no connection to the web server open. So the way to think about it, is that you have a javascript application running in your browser. A traditional form, when submitted, is a new request to the server. Depending on if it's GET or POST method, a new HTTP request gets sent, the browser waits for the response, and the entire DOM is rebuilt based upon the response data, which is going to be more HTML (along with associated javascript, css etc.). Ajax was added to the DOM api, in order for there to be a way that a page could send and receive data, without this entirely new HTTP request/response. It's an HTTP request through javascript, where the data returned can then be evaluated within the running javascript and used to update the page. So ajax is an alternative to standard HTTP request/response, typically with forms, but now, with many other aspects of dynamic DOM manipulation with javascript. So, hopefully that helps you understand ajax, and why it is extremely beneficial and useful in modern web applications. In this case, it is absolutely not needed. So to go back to the page in your browser, that page is running locally as an application hosted within the browser. It has to be able to handle mouse and keyboard events, and unless it's a standard click on a link, or a submit button for a form, there won't be a new http request generated by default. What you have is a form, where you have rendered a table inside of it with a series of HTML form elements to be filled in. You want to be able to add a new set of these form elements, and all that is required there is javascript, running locally to dynamically manipulate the DOM and add a new row to the table with a new set of table elements. jquery is the grandfather of javascript frameworks. It was designed to make it easy for people to do DOM manipulation of the type you need, and it also has functions that make ajax easy. Most developers who have been around a while, have probably used it in the past, and it was part of the first really popular css ui framework (Twitter Bootstrap). It's got a lot of capabilities, but it's also a bit bloated by today's standards. As things have evolved and changed in the javascript UI world, a lot of other libraries and javascript frameworks have emerged, and many of the things jquery was used for in the past are being done instead with a framework like react or vue. So I won't show you how to do this in jquery, since if you already aren't using it in some way, I won't suggest to start down a path that isn't being used for new development. Here is some simple javascript that will dynamically add a new row to an existing table. It isn't exactly matched to what you have now, but is based on it. function addRow() { console.log('clicked addrow'); const table = document.getElementById("form_wrapper"); const row = table.insertRow(1); let c1 = row.insertCell(0); let c2 = row.insertCell(1); let c3 = row.insertCell(2); let c4 = row.insertCell(3); c1.innerHTML = '<label>Item:</label><input type="text" class="item" size="5" name="item_number[]">'; c2.innerHTML = '<label>Desc:</label><input type="text" class="description" size="20" name="description[]">'; c3.innerHTML = '<label>Qty:</label> <input type="text" class="quantity" size="3" name="quantity[]">'; c4.innerHTML = '<button type="button" name="add_row" onclick="addRow()">+</button>'; } Here's a codepen, for demonstration purposes: https://codepen.io/gizmola/pen/jOQLKBd I think you'll find that this use of document.getElementById, is the most common way to select an item that has an id attribute. There should only ever be one element on a page with that id, so it's perfect for selecting the table. Once you have the table element you can dynamically add a new row, and the cells you need.
  5. I don't think you understand rewrites. Rewriting in this way allows you to use a non-existent url like /slugname/ to the scripts that can actually process them. You can't "rewrite" the actual scripts to a non-existent url. They could never be resolved. Rewrites are not magical "rewrite my url's to the rest of the world on the fly". It's the responsibility of your markup and code to display your url's in the virtual/ pre-rewritten form you want users to see them. If I've misunderstood your statement, please let respond with a specific example as in: Client sends https://www.domain.com/a/ ---> Server rewrites to https://www.domain.com/page.php?slug=a
  6. The fields that are part of the result from 4 joined tables, isn't really important in comparison to the number of rows in the result set, and any limiting where clause criteria. As @requinix stated: EXPLAIN query... is your analysis tool. We'd need to see the query and its explain plan to offer further insight. Many times, if performance is bad, you'll be able to see the reasons in the explain. Depending on the criteria, adding a covering index might solve your performance issue, but the only way to know for sure is via the explain. You want to take a look at the rows and key columns to see how many rows are being examined, and what indexes (if any) are used in generating the final result.
  7. There are different strategies for handling multiple entries, but the one employed most frequently is to implement some javascript that will allow you to add a new form group to the table dynamically, using an "Add another item" button or something similar. Rather than trying to make the input names unique, utilize array name syntax like so: echo '<td><input class="item" name="item_number[]"></td>'; Once you do this, $_POST['item_number'] will be an array, and you can foreach() through it to validate data and do as many inserts as you have validated items. Hopefully, it is clear that you will use the array syntax with all the fields, and when you dynamically add a new input row, be sure to also use that syntax for the dynamically created row/input group.
  8. Gonna throw out my best guess here, based on the snippet and some variable naming, that OP has gotten a script designed to be run from the cli, that automates interaction with some crypto faucets. OP didn't write the app, doesn't really know PHP, isn't likely to learn it, and is just trying to run this script to get it running as a means to an end. Script contains features designed to isolate it from anything else that might be running on a server offering PHP.
  9. PHP is in a pretty good place now, and is a very different experience than what it was 10 years ago. With that said, it's really not a highly used Devops/sysadmin language. Neither is Perl, for that matter. Devops, and the emergence of the practice of Devops will likely be new to you. It's where system administration has evolved to. Here are the main take aways in my opinion: Virtualization/The Cloud is pervasive Much of hosting is done on virtualized servers. So familiarity with the different types of virtualization is highly valuable In addition/ Containers (Docker, Kubernetes, etc) have been taking over application development, and increasingly production deployments DevOps makes git and hosted git repositories a core component of deployment and administration. You have to know git well, and the options for hosted git like github, gitlab and bitbucket DevOps groups use Hashicorp Terraform for "infrastructure as code" to setup/teardown/alter complicated environments in the cloud The tools for additional provisioning and maintenance of servers continues to evolve Chef and Puppet were both popular and continue to be used by many orgs, but Ansible and Salt(stack) have emerged as alternatives for automation of administrative tasks Ansible and Salt are both written in Python Chef is written in a combination of Ruby/Erlang Puppet was originally written in Ruby, but has evolved into a hybrid c++/clojure/ruby product Once you start using any of these provisioning/admin tools, you end up focused on their recipes/modules and in some cases, you might be able to extend them, or use elements of the core language. Notice that there is no java/javascript/php or perl to be found in this list. I don't mean to discourage you from jumping into modern PHP development, but it has to be said, that it's not a big player in the world of System administration/Devops, so you might be better off learning Python & Ansible if you plan to get back into hosting & system administration.
  10. Add some extra checks in to prevent the rendering of dates in the table if they are in the past. This should work: <section class="content" id="termin"> <?php $dt = new DateTime; $thisWeek = $dt->format('W'); $thisYear = $dt->format('o'); if (isset($_GET['year']) && $_GET['year'] >= $thisYear && isset($_GET['week']) && $_GET['week'] >= $thisWeek ) { $dt->setISODate($_GET['year'], $_GET['week']); } else { $dt->setISODate($dt->format('o'), $dt->format('W')); } $year = $dt->format('o'); $week = $dt->format('W'); ?>
  11. I don't understand the question. You created the table with code to have a range of days and times. Your code created the table. What would you want to be different about the days or times output?
  12. HTML5 date inputs have a min/max attributes you can set. See the mozillla page.
  13. You need to define what "not working correctly" means. $mail->Host = 'localhost'; This tries to send mail through your server. That is not going to work. With godaddy, you need to send your email through their mail servers. Typically they provide that information to you in some fashion.
  14. This is going to be a little more complicated with your date string, because you will need to turn the date string back into a valid javascript date, so that you set your form date element value. See if you can figure out how to do that. I'll give you a hint, on how to strip out the <br> tag from the date string, leaving you only with the text. function MyFunction(col, time) { const tbl = document.getElementById("myTable"); let dateValue = tbl.rows[0].cells[col].innerHTML; console.log('dateValue: ' + dateValue); dateValue = dateValue.replace('<br>', ' '); let dateEl = document.getElementsByName("tDatum"); let timeEl = document.getElementsByName("tVreme"); dateEl[0].value = dateValue; timeEl[0].value = time; } Another hint: google for javascript Date.parse()
  15. You should see a pattern by this point, in terms of how you select a dom element in html. So long as the element has an id, you can use: let someVar = document.getElementById('someId'); So that is one way. You did not give your form elements id attributes. It would be simpler if you did in this case. However, there are other ways to select an element into a javascript variable. Since you did use name attributes, you can use that. However, the same name can be used for multiple elements, so you would need to do this instead. function MyFunction(col, time) { const tbl = document.getElementById("myTable"); let dateValue = tbl.rows[0].cells[col].innerHTML; console.log('dateValue: ' + dateValue); let dateEl = document.getElementsByName("tDatum"); let timeEl = document.getElementsByName("tVreme"); dateEl[0].value = dateValue; timeEl[0].value = time; } You reference the 0th element in the arrays returned by getElementsByName, which is fine in this case, because we know that there is only one form element with that name in your html document.
  16. The time is being passed as the 2nd parameter as a string. In my function it was named time. If you console.log('Time:' + time); you should see the value.
  17. Pictures of code don't help either of us. If you need to, you can paste your code into the forum here, or you can use a pastebin like the one on my site here: https://forum.gizmola.com/pastebin/
  18. You also did not see that I did not provide you the complete code for setting the 2 form element values. Prior to adding that code you first should console.log the values inside MyFunction so that you can test that the onclick is doing what you want it to do. <script type='text/javascript'> function MyFunction(col, time) { const tbl = document.getElementById("myTable"); let dateValue = tbl.rows[0].cells[col].innerHTML; console.log('dateValue: ' + dateValue); } </script>
  19. To be clear that refers to changes to the timeslots function. Put that back to the way it was in your original post.
  20. As for it disappearing, there's clearly some bug in your code. I don't know exactly what your code looks like, but you need to debug the html using devtools, to see what has gone wrong. You should revert the changes suggested by Barand, back to your original code if you plan to use the ideas I have proposed. They are based on your original code.
  21. Also, you have not given your table an id. In my example, it would need to be <table id="myTable">
  22. No you missed the fact that the column needs to be incremented for each cell. MyFunction(0, MyFunction(1, MyFunction(2, ... MyFunction(6,
  23. This is why I linked you to the github project. Did you take a look at it? Clone and run it locally? Try and understand what it does and how it is designed? It's essentially a sort of PHP SPA. If you look at all the functions I had to add for the simple routing and handling of the form, you get an idea of what a routing class, or the HTTP classes that lots of projects (Laravel included) borrow from the Symfony components. In summary, frameworks are a collection of different component classes, usually with things like configuration figured out. My demo project includes use of a "dotenv" processing class, which is best practice for web app configuration of things like database credentials which should not be hard coded and stored in your source code repository. You don't have to use use an entire framework, but instead can use components you find helpful. Also, again, DBAL wraps PDO. By using DBAL, you will be using PDO, only in a simplified form. It has some very nice features, one I illustrated and documented. When you use symfony or laravel, you won't be using PDO directly -- you use their ORM that then uses PDO for you. My project would have been even smaller and simpler if I'd used the Symfony Http foundation component. My point is, that modern PHP development should always start with the user of composer, and a skeleton directory setup with a /public directory where directly executable scripts will go. All classes should go into either your own component, or in an app space. You make at most a few modifications to the composer.json, and as you develop, rely on composer to generate the autoloader you need, which you include in any of the script that directly execute within /public. An alternative to that is to create a bootstrap include that does the same thing, and include that in all your directly executable scripts.
  24. Please read my updated post. It has nothing to do with the database. It is the way you created the html table of dates and times. The dates in the first table row are in no way connected to the times, and I don't think Barand saw that. If you had one unified computation that would be a better solution, but I basically provided you a hacky way of getting to where you want to be, albeit in a less elegant way. Using data-* elements are a better practice for connecting static data to html elements, which would be simpler, but you would also have to rewrite things that already work for you, and I would suggest you just get it working with what you have.
  25. You have painted yourself into a bit of a corner because the Dates computed in the first row are disconnected from the time period slots. When you click on a cell in the table, you not only need to determine what the time period is, but also what day that time period is relevant to. This is essentially what Barand is trying to help with. While I agree that would be a great solution, I don't think he realized that the timeslots don't correspond with the dates, so this is not going to work, until a connection is made between the two. One way to get around this would be to use javascript to get the date value from the first row, and the corresponding column inside MyFunction. To facilitate this you should give the table an id, so you can select it easily. Then you can do something like: function MyFunction(col, time) { const tbl = document.getElementById("myTable"); let dateValue = tbl.rows[0].cells[col].innerHTML; // Set the Form Date element value using dateValue // Set the Form Time element value using time ) Change the table output to something like this: <td><a href="#" onclick="MyFunction(0, '<?php echo $ts; ?>');return false;"><?php echo $ts; ?></a></td> <td><a href="#" onclick="MyFunction(1, '<?php echo $ts; ?>');return false;"><?php echo $ts; ?></a></td> etc.
×
×
  • 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.