-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Option 1, yes just a SQL view. You could create a query that will left join the account_settings table and generate a result set that contains each setting and the value from the account_settings table if set, or the default value from the setting if not. You could then map that view to a read-only entity and add it as a relation to your account entity. Option 2, yes a service i just some class that you use to perform some task which is accessible via the container/dependency injection. Most things are "just normal php code", they just get categorized based their purpose. In general Services are code that generally implement your business logic; Controllers handle the your HTTP requests, generating responses and collecting input data; Entities/Data objects are simple data structures for moving data around the system in an organized way (vs just array's everywhere for example). Not really sure what you mean by the new wrinkle, so no advice there I guess.
-
Your script is probably getting stuck here: $dataOut = fgets($f); It's waiting for data from your serial device but the device isn't sending any data so the script just hangs there waiting indefinitely. You'll have to add some debug logging or something to figure out why or if that's actually the case. You could also try implementing non-blocking IO and a timeout.
-
The structure seems fine to me. For the doctrine/symfony integration I see two possible approaches. Create a view that you can query against to get the configured value for a setting (either the value in account_setting or the default value) and then make a read-only entity based on that view. Changing a setting would require creating/updating an entity for the underlying account settings table rather than the read-only entity. Create a service that you can use to query for a setting. The service would check for a account setting first, then fall back. You could have the service load all the relevant data on the first inquiry rather than run separate queries on each inquiry. The service could also include the code needed to create/update account settings. I'd probably go with option #2. It keeps the code for settings more centralized and consistent.
-
You need your join on the second table to be a LEFT JOIN, but right now you're just making it a regular (INNER) JOIN. An inner join excludes the row from the result if no match is found in the second table. A left join will include the row, but with all the fields from the second table set to NULL. I don't know code igniter, but a simple search for code igniter left join suggests you want to write your join as: $this->db->join('crm_clients_users c','t.agent_id = c.id', 'left');
-
If someone decides to be funny and set $_GET['page'] to "-42" you don't end up with messed up calculations. Using max, any number <= 0 will get ignored and $page will get set to 1 instead. If you calculate your total page count you should do a min($totalPageCount, $page) as well so that $page doesn't get set to something larger than $totalPageCount.
-
Rather than passing two variables in the URL, just pass one called 'page'. You can use that to calculate your $to/$from variables. $recordsPerPage = 10; $page = max($_GET['page'], 1); $from = ($page - 1) * $recordsPerPage; $to = $from + $recordsPerPage; For the previous button, disable it if $page == 1. To handle your next button, you need to do a query to count the total possible results. Take the same query you'd use to obtain your paginated data and remove the LIMIT clause and replace the selected columns with CEIL(COUNT(*)/10) as totalPages. Once you have the total page count you can compare it to $page to determine whether or not to enable the next button.
-
For future reference, rather changing the value of display directly like that, it's easier to just add/remove a class which will apply display: none; Doing it that way, you don't have to worry about whether it should be 'block', 'inline', 'table-cell', 'grid', etc. You just apply display: none; with a class to hide it, then remove the class so display: none; gets removed and it falls back to whatever the previous value was.
-
PHPStorm is what I use, but the price may put it out of consideration for any non-professional. Editplus is what I used to use before PHPStorm. I still keep it around as it's a nice general-purpose text editor. The price is low and it's one time payment for the most part. Might have to pay again for a future version if you want to upgrade years down the road (minor versions and next major version upgrade are included with original purchase). Notepad++ is what I tend to use if I just need to download an editor for a short period of time.
-
Create composer package which requires another package
kicken replied to NotionCommotion's topic in PHP Coding Help
Have a look at the composer's documentation for vendor binaries and maybe scripts. By adding a script to your project, you could run your command via something like composer attribute-validator. If you add the vendor/bin path to your PATH then you could just run attribute-validator directly. -
Create composer package which requires another package
kicken replied to NotionCommotion's topic in PHP Coding Help
Your composer.json file defines two require keys. The first one has your intended requirements, the second later on is empty. The empty one overrides your first one. -
Your foreach loop will run to completion (ie, print every row) before your while loop condition gets re-evaluated. In pseudo-code, what you wrote is this: while $counter < 8 for each result $row print $row increment $counter end end Where as what you want to write, is while $counter < 8 fetch next result $row if $row exists print $row end increment $counter end There are multiple ways to write that. One way is to fetch a row at a time rather than everything. Another is to fetch it all like you are now, but break; after the 8th row.
-
Could be a firewall problem (error 113 = no route to host). Talk to your host, or check your firewall if you're managing your own hosting.
-
Add event to an element created with javascript
kicken replied to raduenea's topic in Javascript Help
You need to use a delegated event which involves Adding the event to some parent element that will always exist and Adding a selector argument when calling the .on method. $('#tableDiv').on('click', '#edit', function(){ alert('Hi!'); }); -
The complexity here come from trying the add/remove your one-time cron jobs. Cron isn't really designed for this type of usage so making it work this way would take a fair bit more effort on your part than doing the traditional way. Have you considered using at rather than cron? It seems to fit your scenario better.
-
No, you're still executing your query as part of the loop condition: which means you run it again on every loop iteration. You need to run the query once before the loop, then call fetch_assoc() on each iteration of your result loop.
-
You're not trying to use a return value from your query method in that code. Notice the line containing the call to query doesn't contain a $something = in front of it. You're DB::getInstance() method does return a value, which gets assigned to $user in that code. In the single-line version of the code, the value returned by DB::getInstance() is not captured, just used temporarily for the call to query. If you wanted a multi-line equivalent of your single line version it would be: $tmp = DB::GetInstance(); $user = $tmp->query('...'); if($user) { echo "success -> "; } else { echo "fail -> "; }
-
Log your dataResult variable before you try and parse it. console.log(dataResult); Sounds like it's incomplete, you need to figure out why.
-
Refreshing the page after uploading files to folder using dropzone
kicken replied to michelle1404's topic in PHP Coding Help
Try the queuecomplete event. -
Your query method does not return anything, so $user will be NULL.
-
What is your code for DB::getInstance() and your query() methods?
-
Sounds like you need to either split the functions into different pages or learn enough Javascript to do background requests and update the current page. The Javascript you need wouldn't be that hard probably. Either load up jQuery and use it's ajax functions or learn how to use fetch() and update the page with the DOM. There probably is, but as of yet we don't really have enough info about the overall process to be of much help.
-
Create a script that checks the database for the content. If the content exists, display it in whatever manner you want. If the content doesn't exist, have the page refresh itself after 5 seconds.
-
You can't get just decide to access an instance-level property as if it were a static property. The whole thing with static properties and methods is that there is no instance so instance-level stuff cannot be used. You either need to setup a static property for your connection or pass the connection into your static method as a parameter.
-
Based on how you're trying to use it, you would just pass along the data to PDO's prepare method. public function prepare($sql){ return $this->conn->prepare($sql); } There's not much benefit to that over just dealing with PDO directly. This is why I suggested earlier that you might be better off for now just dealing with PDO and drop the whole idea of having a Database class. All your database class is managing to do so far is get in your way and confuse you.
-
Make it a named function, then pass the name to your event handlers. function loadData() { $.ajax({ type: 'POST', url: 'returnPDO.php', dataType: "json", data: { id: "1", rows: "7" }, success: function (data) { ...CODE.... } }); } $("#searchTbl").keypress(loadData); $('#go').on('click', loadData);