While writing code in a file that would comprise of PHP, HTML, CSS & JavaScript, in what order each must appear? What are the best practices for separating the presentation and the logic? Sometimes external .js and other files are using in the link tag. Where these link tags must appear? Answer This doesn…
MySQL datetime fields and daylight savings time — how do I reference the “extra” hour?
I’m using the America/New York timezone. In the Fall we “fall back” an hour — effectively “gaining” one hour at 2am. At the transition point the following happens: it’s 01:59:00 -04:00 then 1 …
How do I remove a comma off the end of a string?
I want to remove the comma off the end of a string. As it is now I am using but that only removes the last character of the string. I am adding the string dynamically, so sometimes there is no comma at the end of the string. How can I have PHP remove the comma off the end of the
Duplicate a record in MySQL
I have a table and I want to duplicate specific rows in the table. I know this is not the best way to do things but we are looking for a quick solution. Here’s something harder than I initially thought, all I need to do is copy an entire record to a new record in an auto-increment table in MySql
Function inside a function.?
This code produces the result as 56. function x ($y) { function y ($z) { return ($z*2); } return($y+3); } $y = 4; $y = x($y)*y($y); echo $y; Any idea what is going inside? I am …
MySQL: Join query across multiple databases located on different servers
In SQL Server there is a way to join tables from multiple sql servers by using link tables. I wonder whether is it possible to do the same? I am using PHP, does PHP provides this kind of facilities? Answer It isn’t necessarily easy, nor pretty, but this article gives some solutions to your problem: http…
How to get the first item from an associative PHP array?
If I had an array like: And I wanted to get the first item out of that array without knowing the key for it, how would I do that? Is there a function for this? Answer reset() gives you the first value of the array if you have an element inside the array: It also gives you FALSE in case
Passing variable argument list to sprintf()
I would like to write a function that (amongst other things) accepts a variable number of arguments and then passes them to sprintf(). For example: <?php function some_func($var) { // … $s =…
Pattern Match on a Array Key
I need to get the stock values out of this array: I need to pattern match on this array, where the array key = “stock” + 1 wildcard character. I have tried using the array filter function to get every other value on the PHP manual but the empty values seem to throw it out. I tried alot of differen…
netcat “Connection refused” on localhost
I’m trying to get a value from a netcat connection started at a php file, but it dies with: I don’t know why but it works well if I ssh it as apache user (www-data), this is what I’ve done: 1) Start an endless loop serving a date with a little delay: 2) Check if is working: 3) Create /var/ww…