-
Who's Online 1 Member, 0 Anonymous, 82 Guests (See full list)
All Activity
- Past hour
-
MartinPeck joined the community
-
Hello - sincerely hoping someone out there will be able to help with this, or at least have a good idea on what's going on. I have created a 'Single Page Application' (SPA) type website, and have used PHP on the server-side. At present, nearly all my content files (XML, JPEGs, XSLT, CSS) are generated from PHP scripts. My design uses many source files, and some pages have many small images, so file caching by the client browser is very important. I have set HTTP Cache-Control response headers on everything, to inform the browser that it can and should cache everything. (Content changes get picked up when a version number changes in the URL.) So far, so good - or so I thought. My problem is that both Safari and Chrome on iOS do fresh requests of EVERYTHING that's come from PHP, every time the user opens the phone from screen-lock. So the site is fast and slick with everything loaded into cache, until a 20 second pause with the phone locked, and then everything is dog slow again the first time content is viewed. For my use-case, this is a huge usability (and server load) problem. I've noticed that this refreshing of content DOESN'T happen for regular static files. (I have a folder of static file PNG images, and these never get re-requested.) How can I make all the PHP-generated content appear to the browser to be static files, so that the browser's heuristics don't mistrust them and assume they will be changing despite the HTTP headers?????! I can't believe I'm having this problem, honestly. Never seen anything like it before, with browsers ignoring these Cache-Control directives. There's something really messed up with the logic on mobile devices....
- Today
-
Technical Side: if you want to retain ownership of the code you create, it's crucial to spell that out clearly in a contract before any work begins. You can license the use of the system to the client instead of transferring full ownership. business standpoint: In the U.S. work-for-hire rules, typically favor the client if you're an employee, However, if you're an independent contractor (freelancer), you usually own the IP until you sign it over, so having a solid contract is everything. you could approach it two ways: - Hourly rate: $50–$150/hr - Flat project fee: $2K–$5K range maybe think about offering ongoing maintenance for a monthly fee, it keeps you tied into the project and builds long-term income.
- Yesterday
-
Pamir5514 joined the community
-
you should do this directly in the sql query statement. MySql has a large number of datetime functions. what is the format of the 'date' column in the database table? if you do this in the php code, you must either compare objects with objects or compare formatted strings with formatted strings, with the same exact format, in a left-right order from most significant field (year) to least significant field (day.) the current php code produces a fatal error at the date_diff() method call, because the 2nd argument must be an object, not the $data["date"] string. $date is a datetime object, you cannot directly compare it with the $data["date"] string. you either must use the datetime ->format() method to produce a formatted string from the $date object, or you must create a datetime object from the $data["date"] string. $diff in a dateinterval object. to get the number of days, you would need to use the dateinterval ->format() method with the '%a' format specifier to produce the whole number of days.
-
rwahdan1978 joined the community
-
Hi, I have this code that I am trying to check between 2 dates. the first date taken from DB abd the second date is currect date. I want to compare between them (how many days left, it is not working. <?php include('connect.php'); $sqlSelect = "select dueDate as date from subscriptions"; $result = mysqli_query($conn,$sqlSelect); $date = new DateTime(date('d-m-Y H:i:s')); while($data = mysqli_fetch_array($result)) { $diff=date_diff($date,$data["date"]); if( $data["date"] > $date && $diff < 15) { print("ok"); } } ?> How to go about this?
-
Gamilo599 joined the community
- Last week
-
RewriteEngine on RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www.thelogos.net$ RewriteRule ^(.*)$ https://thelogos.net$1 [R=301,L]
- Earlier
-
I still have to solve this problem. I will share the code with you as soon as I access my system. appreciate your response.
-
Hopefully, it's clear to you that Barand's solution and the one I presented are the same, only Barand used a 100% functional approach, and a lambda (anonymous function) passed to array_map. Compare/contrast the two solutions, and if you can understand them both, you'll have a good basis for solving future problems like this. One thing I would note about these solutions, is that any solution is only as good as its suitability to the data. For example, if the names can have suffixes like jr, sr, 3rd etc, you'll probably not get what you want. They could be improved to handle those situations, should the data you're working with warrant it. Using PHPUnit to create unit tests for code like this is a really valuable investment, if you care about testing, maintainability and quality.
-
I strongly recommend that you change all of your tables to use the InnoDB engine. It's currently the default engine, given that it provides superior performance and features. Any aspect of a table can be changed (no dropping required) using the ALTER TABLE syntax.
-
INSERT INTO `Bank_Reason` (`ID`, `ReasonID`, `Reason`,`Colour`) VALUES (1, 0, '---SELECT','#000000'), (2, 1, 'Other',','#0000ff'), ^^ Again!?
-
I fixed the wrong quote but there is still an error. When I put the code into Notepad++ Line 8 is a blank line under create table section. MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(3, 2, 'Virgin Bank','#000000'), (4, 3, '_Spare_2','#000000'), (5, 4, 'CT','#f' at line 8 DROP TABLE IF EXISTS `Bank_Reason`; CREATE TABLE IF NOT EXISTS `Bank_Reason` ( `ID` int(11) NOT NULL, `ReasonID` int(11) DEFAULT NULL, `Reason` varchar(20) DEFAULT NULL, `Colour` varchar(8) DEFAULT '#000000' ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `Bank_Reason` -- INSERT INTO `Bank_Reason` (`ID`, `ReasonID`, `Reason`,`Colour`) VALUES (1, 0, '---SELECT','#000000'), (2, 1, 'Other',','#0000ff'), (3, 2, 'Virgin Bank','#000000'), (4, 3, '_Spare_2','#000000'), (5, 4, 'CT','#ff00ff'), (6, 5, 'Energy','#c51010'), (7, 6, 'Mobile','#27b30b'), (8, 7, 'Virgin_BB','#06b8b6'), (9, 8, 'MNOPF','#00aa00'), (10, 9, 'Water','#aa7700'), (11, 10, '@Shops','#ff0000'), (12, 11, 'Online','#7777ff'), (13, 12, 'Cash','#000000'), (14, 13, 'Pablo','#000000'), (15, 14, 'Amazon Prime','#000000'), (16, 15, 'Ebay/Paypal','#7a061c'), (17, 16, 'Argos/Store cards','#000000'), (18, 17, 'Alexa Music','#000000'), (19, 18, 'HSBC','#aa00aa'), (20, 19, 'Amazon Orders','#aa7700'), (21, 20, 'State Pension','#301de8'), (22, 21, 'Home Insurance','#000000'), (23, 22, 'Lottery','#000000'), (24, 23, 'Rent','#000000'), (25, 24, 'Private Health','#000000'), (26, 25, 'Credit card **','#000000'), (27, 26, '_Spare_1','#000000');
-
INSERT INTO `Bank_Reason` (`ID`, `ReasonID`, `Reason`,Colour') VALUES ^ | unwanted single quote
-
Hi. I have an exsisting table Bank_Reason. I want to add an extra columb 'Colour' to it. I am getting an error when I try to change it. I have done a drop table and recreate. Can any help with this extra columb please. I worked fine before. P.S. I have noticed that i was missing a (`). NEW line INSERT INTO `Bank_Reason` (`ID`, `ReasonID`, `Reason`,`Colour`) VALUES. Makes no diffrence. DROP TABLE IF EXISTS `Bank_Reason`; CREATE TABLE IF NOT EXISTS `Bank_Reason` ( `ID` int(11) NOT NULL, `ReasonID` int(11) DEFAULT NULL, `Reason` varchar(20) DEFAULT NULL, `Colour` varchar(8) DEFAULT '#000000' ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `Bank_Reason` -- INSERT INTO `Bank_Reason` (`ID`, `ReasonID`, `Reason`,Colour') VALUES (1, 0, '---SELECT','#000000'), (2, 1, 'Other',','#0000ff'), (3, 2, 'Virgin Bank','#000000'), (4, 3, '_Spare_2','#000000'), (5, 4, 'CT','#ff00ff'), (6, 5, 'Energy','#c51010'), (7, 6, 'Mobile','#27b30b'), (8, 7, 'Virgin_BB','#06b8b6'), (9, 8, 'MNOPF','#00aa00'), (10, 9, 'Water','#aa7700'), (11, 10, '@Shops','#ff0000'), (12, 11, 'Online','#7777ff'), (13, 12, 'Cash','#000000'), (14, 13, 'Pablo','#000000'), (15, 14, 'Amazon Prime','#000000'), (16, 15, 'Ebay/Paypal','#7a061c'), (17, 16, 'Argos/Store cards','#000000'), (18, 17, 'Alexa Music','#000000'), (19, 18, 'HSBC','#aa00aa'), (20, 19, 'Amazon Orders','#aa7700'), (21, 20, 'State Pension','#301de8'), (22, 21, 'Home Insurance','#000000'), (23, 22, 'Lottery','#000000'), (24, 23, 'Rent','#000000'), (25, 24, 'Private Health','#000000'), (26, 25, 'Credit card **','#000000'), (27, 26, '_Spare_1','#000000');
-
$surname_counts = array_count_values(array_map(fn($v)=>substr($v, strpos($v, '_', 0)+1), $names)); -> Array ( [jones] => 2 [smith] => 3 [doe] => 2 [jackson] => 1 )
-
I really have no context with which to give you a "best solution" but a longstanding way of handling this is to have the customer website utilize an iframe that wraps your hosted site.
-
To a degree, because you can create your desired list/count in one pass through the array. <?php $names = ['bob_jones', 'sam_smith', 'jane_doe', 'john_smith', 'jill_jackson', 'matt_jones', 'john_doe', 'emily_smith']; $lastNames = []; foreach ($names as $name) { $lname = substr($name, strpos($name, '_') +1); if (array_key_exists($lname, $lastNames)) { $lastNames[$lname]++; } else { $lastNames[$lname] = 1; } } var_dump($lastNames);
-
if you post the code generating the array, someone could post an example, instead of just writing about how to do it.
-
Correct. No database involved. The array is generated from other PHP coding.
-
From the way the question was worded, it doesn't appear that the data is in a relational database.
-
if all you want is a COUNT() per last name, you can do that in the query that's getting the data, with a GROUP BY last_name term. if you want the name data and a count for each last name, i would index/pivot the data using the last name as the main array index when you fetch the data, from wherever it is coming from.
-
I have an array of first and last names joined by an underscore (eg: Sally_Smith). Ultimately, I want to count the number of people (elements) with the same last name. My thinking is to run through the array and explode each element to isolate the last names, then use array_unique to create an array of $lastNameOnly and eventually use this as a counting mechanism against the original array.. Am I over-complicating this?
-
@gizmola I appreciate all your help. Now I think we've come full circle and returned to my initial conundrum. If the business already has a minimal web presence with a registered domain, how can I incorporate MY form without making ripples in the pond. If I host it myself, then users are being re-directed. And if I put my code on the business domain server, then I no longer have exclusive access to it. What is the best solution for me?
-
As requinix stated, not really with css, because css "styles" markup. You could inject an additional DOM element using javascript. I'm not suggesting that is a good idea, but it would work fine, especially if this "row" is static.
-
If the form is a "web form" then host it, and store the data within your own infrastructure, and you've accomplished SaaS, with all the benefits of code ownership we've discussed. You do need to account for the fact that you'll be paying for hosting. There are many solid/reputable hosting companies that provide a virtual server with room to grow your application, where you'll know your price in advance. You also want the server to be in a DC that is co-located near to your customer, and these mid size hosting companies tend to have that type of coverage. Linode, Vultr, Hetzner and Contabo are a few of the better known companies with track records to compare and contrast. I would highly advise against using shared hosting. Given that you will be running a monolithic architecture, I'd suggest looking at 8gb vps's to give you room to run the mysql database as well as your webserver/php stack.
-
@gizmola As stated, just starting with a simple form to register users and collect information (eg: name, address, email, phone) for an easy access point that might be used later for sales' campaigns. I guess the real question is: How do I optimize my earrings and ensure that I don't have my work ripped-off by unscrupulous sources?