Jump to content

gizmola

Administrators
  • Posts

    6,000
  • Joined

  • Last visited

  • Days Won

    151

gizmola last won the day on February 20

gizmola had the most liked content!

7 Followers

About gizmola

Contact Methods

  • Website URL
    http://www.gizmola.com/

Profile Information

  • Gender
    Male
  • Location
    Los Angeles, CA USA

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

gizmola's Achievements

Prolific Member

Prolific Member (5/5)

354

Reputation

69

Community Answers

  1. From the looks of it, you are simply unclear on how PHP arrays work, and the syntax involved. PHP arrays are highly versatile, in that they combine what in many other languages, requires multiple different data structure types. It is a combination of an Array, a List and a Map, if we were going back to the standard library of C++. Maps are probably the most interesting, in that a map is a structure that has a 'key' = 'value' association. This is different from an array, which is simply a data structure of 1-N elements, indexed numerically. In c and c++ arrays are limited to a data type. Due to strict typing requirements in c and c++ (and other similar "strongly typed") languages, you are constrained in how you assemble, add to and modify an array, but PHP is extremely flexible in essentially letting you store data type or object as a value in an array, and allowing you to nest arrays within arrays any way that suits you. In your example, you presented a series of nested arrays, some being traditionally numeric, and others containing one or more "key/value" elements. The curious thing is that the array you presented is invalid. Notice that your syrup values are missing the => required to define a key/value element. $arr = [ 0 => ["meds" => [ "IV" => 1, "pill" => 2, "syrup" = 3] ], 1 => ["meds" => [ "IV" => 2, "pill" => 4, "syrup" = 6] ], 2 => ["meds" => [ "IV" => 5, "pill" => 5, "syrup" = 5] ] ]; I fixed that for the following example code. Rather than defining this in one shot, consider how you could start with an empty array and arrive at the same structure. <?php function printArr($a, $name='') { echo "$name --------------------------\n\n"; print_r($a); echo PHP_EOL; } $arr = [ 0 => ["meds" => [ "IV" => 1, "pill" => 2, "syrup" => 3] ], 1 => ["meds" => [ "IV" => 2, "pill" => 4, "syrup" => 6] ], 2 => ["meds" => [ "IV" => 5, "pill" => 5, "syrup" => 5] ] ]; printArr($arr, 'Original Array'); // Empty $arr2 = []; printArr($arr2, 'Rebuilt Array'); $arr2[0] = []; printArr($arr2); $arr2[0]['meds'] = []; printArr($arr2); $arr2[0]['meds']['IV'] = 1; printArr($arr2); $arr2[0]['meds']['pill'] = 2; printArr($arr2); $arr2[0]['meds']['syrup'] = 3; printArr($arr2); // Add a new empty array to 1st dimenion of array. This will become $arr2[1] $arr2[] = []; printArr($arr2, '1st Dimension, new index 1. Arrays are zero based'); // Assign value to be new array with key "meds" having a value of an empty array. $arr2[1]['meds'] = []; printArr($arr2); // Set the value of this nested array element to be a nested array $arr2[1]['meds'] = [ "IV" => 2, "pill" => 4, "syrup" => 6]; printArr($arr2); //Set entire element 3 structure in one assignment $arr2[] = ['meds' => [ "IV" => 5, "pill" => 5, "syrup" => 5]]; printArr($arr2, 'Array complete'); echo "Comparisons ---------------------\n"; echo $arr[0]['meds']['pill'] . PHP_EOL; echo $arr2[0]['meds']['pill'] . PHP_EOL; echo "\n\n"; foreach($arr[2]['meds'] as $nestedKey => $nestedVal) { echo "$nestedKey = $nestedVal\n"; } echo "\n\n"; foreach($arr2[2]['meds'] as $nestedKey => $nestedVal) { echo "$nestedKey = $nestedVal\n"; } The Results: Original Array -------------------------- Array ( [0] => Array ( [meds] => Array ( [IV] => 1 [pill] => 2 [syrup] => 3 ) ) [1] => Array ( [meds] => Array ( [IV] => 2 [pill] => 4 [syrup] => 6 ) ) [2] => Array ( [meds] => Array ( [IV] => 5 [pill] => 5 [syrup] => 5 ) ) ) Rebuilt Array -------------------------- Array ( ) -------------------------- Array ( [0] => Array ( ) ) -------------------------- Array ( [0] => Array ( [meds] => Array ( ) ) ) -------------------------- Array ( [0] => Array ( [meds] => Array ( [IV] => 1 ) ) ) -------------------------- Array ( [0] => Array ( [meds] => Array ( [IV] => 1 [pill] => 2 ) ) ) -------------------------- Array ( [0] => Array ( [meds] => Array ( [IV] => 1 [pill] => 2 [syrup] => 3 ) ) ) 1st Dimension, new index 1. Arrays are zero based -------------------------- Array ( [0] => Array ( [meds] => Array ( [IV] => 1 [pill] => 2 [syrup] => 3 ) ) [1] => Array ( ) ) -------------------------- Array ( [0] => Array ( [meds] => Array ( [IV] => 1 [pill] => 2 [syrup] => 3 ) ) [1] => Array ( [meds] => Array ( ) ) ) -------------------------- Array ( [0] => Array ( [meds] => Array ( [IV] => 1 [pill] => 2 [syrup] => 3 ) ) [1] => Array ( [meds] => Array ( [IV] => 2 [pill] => 4 [syrup] => 6 ) ) ) Array complete -------------------------- Array ( [0] => Array ( [meds] => Array ( [IV] => 1 [pill] => 2 [syrup] => 3 ) ) [1] => Array ( [meds] => Array ( [IV] => 2 [pill] => 4 [syrup] => 6 ) ) [2] => Array ( [meds] => Array ( [IV] => 5 [pill] => 5 [syrup] => 5 ) ) ) Comparisons --------------------- 2 2 IV = 5 pill = 5 syrup = 5 IV = 5 pill = 5 syrup = 5 If you can look at these results and understand them, you'll have a better idea of how to reference any element in a nested array directly. You can also reference any dimension, going from left to right, where the first Dimension (array) will be $r[], the 2nd dimension $r[][] and so on, for as many nested dimensions as you might have.
  2. First an editorial comment: Please do not take screen shots of code for your questions. We can't use that in our replies or help. We have a code block for a reason. You can easily copy/paste snippets of relative code into the code block, and that makes it possible for us to make edits based on the original code. Nobody here likes having to re-type parts of your code. Paths in your html are relative to the document root. The document root is a function of the web server configuration for the server or vhost you have configured. The types of things you can refer to in an html script are only things that the server understands to have an associated URL. In other words, they are things that you could use a url to access directly from your website. PHP works entirely with files, and file system paths on your workstation. Using PHP code to open include/require files always requires a file system path. When you include a file, the "working directory" for PHP is the path/location in the server file system where the script exists. So to include a php script from another php script you have 2 options: Provide the fully qualified path to the script. Because this path is operating system dependent, you typically don't want to do this as it requires you to add configuration in a file or even edit your source code purely because you moved servers. A Relative Path This is relative, again to the directory where the script that is including this code is. Relative paths can utilize 2 "special files": "." is the current directory. ".." is the parent directory. We don't know what the file system layout is for your project, so we can only guess at the correct path relative to the index.php? or whatever file it is that you are trying to do this php include in is named. If this directory has a sub-directory named "page" and you have put the site-header.php script into that directory, then the relative path you want to use will be: include("page/site-header.php"); This is how you specify a subdirectory path relatively. If you include a leading "/" that is considered the "root" directory of the filesystem. One other thing you might want to do is change include to require_once(). With a require_once() the script will actually error out rather than continue to run along without regard to the fact that your include failed.
  3. We don't have enough information to really help you here. Looking into xenforo, I see that it is a commercial product, with a self host license of $195, and no open source version. Without the source people really can't do any debugging for you. My advice would be to contact the company directly as this is some sort of installation issue, and they are really the only ones in a position to understand the implications of that stack trace.
  4. I'd suggest you try to use php://output directly. $stdout = fopen('php://output','w'); foreach($rows as $row) { fputcsv($stdout, $row); } fflush($stdout); If for some reason this doesn't work (or work reliably) with your host, then I'd suggest writing the data to a file with a temporary name you create using some random input and something like sha1, and then open that file and send it back to the user, but sending it directly to output is a standard solution for this type of requirement.
  5. We get this type of question all the time. Our purpose is to provide a place to mentor and teach people who are genuinely trying to create systems and learn and improve. Everyone has to start somewhere. With that said, it doesn't seem as though the thing you started with is very well designed or suitable to what you are trying to do, but then again we don't really know the details of what you've agreed to provide for your friend or on what timeline. Creating an online reservation system is a non-trivial exercise by itself. OpenTable's cost for their most basic tier of that service is $149/month, so that should tell you something. As a beginner, that is certainly biting off more than you should be in my opinion. The problem with doing something ill conceived or broken equates to literally lost revenue for the restaurant. Let's say that it doesn't work right and people attempt to make reservations and the system doesn't allow them to, or erroneously shows that a reservation can't be made, or double books, or overbooks etc. The result will be people who wanted to come to the restaurant instead going somewhere else. Operationally, the restaurant staff has to be able to (and will be required to) interact with the system throughout the hours of operation. It is no small task, and yet you are approaching this in a way that suggests little thought was invested into this project. Personally, I'd take that right off the table, as just handling the online menu and ordering is already a large job. This also will involve payments and interaction with a payment gateway. Anything less than that, and there is going to be manual entry of things, and storage of credit card data that you aren't legally allowed to perform. So, yes I would agree that you have greatly underestimated this task. From the discussion of this so far, you did not even acknowledge my comments regarding making a lunch_menu and dinner_menu table, which I already told you was a mistake. You thought this was a good idea because you saw that you needed 2 "types" of menus right now. ('dinner', 'lunch'). Let's continue this line of thinking then, and apply it to a menu item. I'm sure that menu items have different categories like ('appetizer', 'beverage', 'main course', 'dessert') etc. So that must mean that you will have at least 4 new tables right? menu_item_appetizer, menu_item_beverage .... etc., right? And that would be a disaster for your project! Here's the reality: any database driven (database connected) system is only as good as the underlying database structure. That is where you should start. Rushing to build out screens and write/modify code and create sql query strings is the wrong way to do this. The analogy I like to use for any rdbms based system is that the database design is like the blueprint for a building, that then becomes the basic structure. If you provide a blueprint for ranch home, you can't then decide later that you really wanted a 3 floor apartment building, and think you're going to have success adding that on top of your existing ranch home. You take the time to have a blueprint for an apartment building. You need a verified and validated database structure 1st. I will say again to be clear: if you need help with your database design (which is clear to me) then you need to provide us the current database structure so we can examine and advise you ASAP. Changes to database structure can be accomplished quickly, but the time to do that is at the start of the project, not after you've written a bunch of code which you will need to change. Sometimes you do need to make adjustments or improvements to the database structure once you are well into development, but you should have, to the best of your ability a structure that supports your needs from the outset, and you probably don't have that now, and have demonstrated you don't understand database design well enough to try and do this on your own without some experienced people advising you.
  6. So your first idea was to make a non-relational goof up. You have a menus table and that should support any and all menus, especially if menu relates to other things. Simply adding a menu_type attribute in menus would have let you designate one from the other and to have other menus (like a happy hour, or thanksgiving, etc) as needed in the future. You literally did what any DBA would tell you not to. You should go back to the drawing board on that. This comes from the database, not from code. In other words, it is data related. You are trying to insert or change data somewhere in the system, which is not in the code you attached, as was already noted by mac in his reply to you. Just looking at that code mac provided a lot of excellent code quality and best practice suggestions, but it doesn't address the disconnect between what you seem to understand or not about your database and how constraints work and what they do. Apparently there is a foreign key constraint on the thaicook3.in_order column, which requires that any value added to the in_order column, must be a menu_id that exists in the menus table. The very names of this table (thaicook3) tells me a lot about how ill conceived this system must be. Having a non-relational schema in a relational database is the road to system ruin. We have a lot of veteran developers that visit phpfreaks who are quite willing to advise and mentor people on how to come up with a proper relational design, that will be easy to use, and allow for a flexible "data driven" system. Scanning the code you did provide, just having queries that contain things like WHERE id <> 9 is one of many examples of things that have been done due to lack of good design, and coding practices. Even if you were to argue that row id 9 in a table is "special" for some reason, you should have that in a constant or at least a boostrapped variable rather than hard coding the magic ID # into queries. There are much better ways (adding columns for example) to allow the system to determine if a row has a special property that should include/exclude it. If your goal is to produce a buggy spaghetti system, then continue on as you are, or you can take the time to socialize the database design with an ERD or even a database dump of the structure, and follow up with some basic requirements.
  7. I'm not clear on what account you have an issue with. In general, if it's anything you really care about, then take the time to set up 2 factor authentication. Emails that claim your account is locked and prompt you to re-authenticate are often Phishing attacks, where you never actually hit the site you thought it was, and for that reason, any emails like that should be ignored, not clicked on. You might want to inspect the original email and see if it was forged. Looking at the email headers and the src of any links usually tells you the story there. Pretty much all sites have now gone to informational messages if they detect changes to an account, or unusual activity. They never prompt you to "login" or to click some link. Email is unfortunately untrustworthy and all emails needs to be viewed with suspicion.
  8. I am 100% in agreement with @jodunno on this. Media Queries is the right way to handle your problem. He provided some great links to look at. I understand that working with old code bases can be challenging. One way to work your way into it is to use a sandbox like codepen or jsfiddle and make a small proof of concept version that has a subset of the overall css and some markup, and just addresses the things you want to change in the UI. Chrome dev tools have a built in way of setting the client dimensions of the browser, to simulate a particular screen size, and there are also some extensions that do the same thing and make it a little simpler. When you first open the developer tools in chrome (using inspect) the first 2 icons let you turn on/off the device toolbar. With it on, you can set the dimesions so it simulates the dimensions of a device or you can manually set the dimensions. Then move those changes over into the new code. Hopefully it wasn't a huge mess of 100 scripts with the html markup copy/pasted everywhere, but even in a case like that, you can add a header.php and footer.php and start require_once() as you remove all the duplicate code. Last but not least, this is why a lot of css frameworks going back to bootstrap got popular fast, as they alll for the most part provide support for making your markup responsive.
  9. Basically what is being described to you is a race condition. You aren't going to be able to hack around it. A PHP script runs on the server, and has "page/request" scope. The client provide an HTTP request, and the server provides an HTTP response, and the connection is closed. Ajax is used to make changes to the state of a fully rendered DOM on the client. You are not going to be able to trick PHP into doing some of its work -- delaying while the client's DOM is in a partial/indeterminate state, in order for ajax to spawn another request, and then have the original PHP script resume in the way you hope it will, all so that you can get access to session variables that didn't even exist when the original HTTP request was made. I have no idea why you are trying to store some client state in a session, given that browser dimensions are dynamic, relative to the device and decisions made by the client. It's not clear what you expect to do with these dimensions, which you're getting from javascript code, but you certainly don't need to put them into a session, and you haven't made an attempt to explain what problem you are trying to solve, but this is not the way to solve whatever problem that is. If you want to actually take the time to explain the "problem to be solved" we might be able to better advise you on ways to solve it.
  10. No. In the code I provided I loop through your array and get each name attribute, then call document.getElementsByName(). As I mentioned what you get back is a nodeList. This is because when you call GetElementsByName the result can be 0 or more nodes, as you are able to use the same name attribute for any number of html elements. In this case, even though that is true, it's your markup and we know that there should only be one node found, and that will be the input that matches the name you passed. As arrays are zero based, item[0] will be the first (and since you control the markup) only element in the nodelist. You can think of it as an array that has only one element in it. As to what you came up with, using eval() should be avoided, as it's highly dangerous to the end user, should there be any possibility that someone can inject a string containing javascript into the string. You continue to attempt to reference part of the DOM document this way, when you already were presented 2 ways NOT to do that, either of which will work. As we don't know the actual form of these numbers that you require for input, we can't really advise you. isNaN by itself is not going to do what you stated you want to do. Here's a couple of examples: let foo = ''; let bar = '0xFF'; isNaN(foo); isNaN(bar); A quick test of these should be of concern to you. If the numbers entered must be integers then mac's Number.parseInt() might lead you to a robust and simple solution. An alternative is to utilize javascript's regular expression syntax. You might also try typecasting values. One thing to keep in mind here, is that in doing what you are doing, as you manipulate these values, you are creating new variables, but the original input values will still be in text form, so even if the data passes through your form validation, the values may be problematic at the point you store them in a database or whatever the app does.
  11. I'm sure he does know that, and we are both motivated by an interest in mentoring and passing along our expertise to people like yourself if we are able. We appreciate the feedback.
  12. I was going to suggest something similar to mac's post, however, I think a better UI choice would be to use AddEventListener to all the fields for the change event using getElementsByClassName to find them. There's an awful lot wrong with what you have so far, not to mention that you have yet to come up with any code that determines if a text input is actually a numeric value. It is deceptively complicated and non-trivial to do so, but that issue aside, what you were asking about could be remedied using code like this. One thing I noted is that you are trying to make a lot of global variables for no particular reason. Try to get in the habit of making as few variables as possible, and use ES6 let and const rather than var (which makes a global variable). What you were missing is the DOM method document.getElementsByName. It returns a nodelist, so make sure you investigate that. I did not try and provide you a solution to your stated goal, but rather, something that moves your work in progress forward, and omits issues with the pattern you are missing. Using this as a form validation means you can't return true for any individual element, but only return true when all elements successfully validate. So you do that by falling through to a return true at the end of the loop. There are several problems even with this code, but hopefully it helps move you forward from where you started. const arrayone= ["it_c","it_h","ot_c","ot_h"]; function hasNumericValue(arr) { // check for numeric values posted in the array of the input fields for (let i = 0; i < arr.length; i++) { let item = document.getElementsByName(arr[i]); let linker = item[0].value alert("Checking Field: " + arr[i]); if (linker == 10) { alert("Value was 10"); } else { return false; } } return true; }
  13. Yes this is common practice. When you first introduce a table you can alias it. You are then free to alias all the columns which can be quite a time saver when you have joined tables together, using "alias.column_name" as Barand did. You can do this explicitly using the 'AS' keyword but you can also omit the 'AS'. It's up to you, but I typically will abbreviate the name in some way, as do most experienced developers, such that your alias is at most a few letters. You should also notice, that he used an alias for the computed columns. Column names can also be aliased, and it's also a common practice. FROM_UNIXTIME(t.time) AS time So in this case you have an example of both alias options being used: thread table was aliased to t Used the t alias to specify the time thread.time field being passed to the FROM_UNIXTIME() SQL function the result of the function being aliased to the name 'time' in the final result set Also time was used in the order by. MySQL allows you to do this (use an aliased column name in an ORDER BY) although not all RDBMS do.
  14. Barry is truly a master of relational database design, implementation and SQL. However , at least initially, a small investment on your part in learning how to join tables together, will dramatically improve your understanding of his analysis and the SELECT statement he provided you. I browsed this material and it's a solid free tutorial on Joins using MySQL. https://www.mysqltutorial.org/mysql-basics/mysql-join/ You may see references to ANSI standard SQL, which is a standard for portable SQL syntax that should be compatible with most relational databases, but I did want to mention that different databases will have features that are specific to their implementation (non-standard), so you might see that in the case of joins there is more than one syntax possible, but they all do the same things. Don't let that confuse you -- JOINS are an essential concept that all relational databases implement. If you have an option, and can use ANSI standard syntax, opt for that, but it really doesn't matter that much, so long as you are clear on what the join produces. A basic understanding of Set theory might give you some insight into the ideas that went into relational database management (union, intersection, difference, subset) might help as well. This article cover the topic pretty well, and you may notice some of the overlap in concept and terminology: https://kyleshevlin.com/set-theory/ It's also worth learning how to read an Entity-Relationship-Diagram (ERD). Once you understand the fundamentals, you should be able to look at an ERD and understand how tables can be joined together. There are also many tools that people use to design or reverse engineer databases. For example, mysql provides ERD design features in their free SQL Workbench tool. ERD's are the way that people socialize a database design, and are the documentation that teams use to document for developers, the database design.
×
×
  • 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.