Try to count total registers in a certain month from members table, but the regdate is in UNIX TIME STAMP. Here is a solution using MYSQL's function FROM_UNIXTIME
SELECT count( * )
FROM `members`
WHERE month( FROM_UNIXTIME( `regdate` ) ) =12
Try to count total registers in a certain month from members table, but the regdate is in UNIX TIME STAMP. Here is a solution using MYSQL's function FROM_UNIXTIME
SELECT count( * )
FROM `members`
WHERE month( FROM_UNIXTIME( `regdate` ) ) =12
A pretty good way to get IP, especially, your site has different servers, i.e. load balancing.
function get_ip(){if (isset($_GET['ip'])) {$ip = stripslashes($_GET['ip']);} elseif (isset($_SERVER) and !empty($_SERVER)) {if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];} else if (isset($_SERVER['HTTP_CLIENT_IP'])) {$ip = $_SERVER['HTTP_CLIENT_IP'];} else {$ip = $_SERVER['REMOTE_ADDR'];}} else {if (getenv('HTTP_X_FORWARDED_FOR')) {$ip = getenv('HTTP_X_FORWARDED_FOR');} else if (getenv('HTTP_CLIENT_IP')) {$ip = getenv('HTTP_CLIENT_IP');} else {$ip = getenv('REMOTE_ADDR');}}return $ip;}
In a project we have a smarty variable presenting a dollar value like ‘1.23’, or ‘.06’. And we wanted to show cent value when the value less than one dollar, for exmaple,
Instead of crating a new smarty variable in php, here is a workaround I made in the template.
{*here $dollar_per is in dollar value*}{if $dollar_per && $dollar_per < 1}{if $dollar_per < 0.1} {*ex. 0.06*}{assign var="cent_per" value=$dollar_per|substr:2} {*get 6*}{assign var="cent_per" value=" "|cat:$cent_per} {*add space before 6 in my case*}{else} {*ex. 0.78*}{assign var="cent_per" value=$dollar_per|substr:1} {*get 78*}{/if}{/if}
Note: substr and cat were used!
There are several attributes of <a> tag, and ‘name’ is one of them. I just found today, that you cannot have character, ‘%’, as a value of this attribute.
I used to use name attribute to hold some data, then pass it as variable in jQuery code as the following,
$(document).ready(function() {$(".s-img>a").hover(function(){var largePath = $(this).attr("name");// note: here I used 'name' attr$("#limg").attr({ src: largePath});return false;},function() {;});});
It failed when the name has ‘%’ character in there. Fortunately, the “alt” attribute is happy with ‘%’as its value. So then, changed it ‘alt’, it works.
P.S. Actually, I see most of ‘alt’ other than ‘name’ to pass variable. Maybe, this is a reason.
I have ajax to set cookie and then reload the page, the original code is some thing like the following:
$('#btn').click(function(){$('#btn').html('Please wait ...');$.get("/ajax/update.php?action=set"); //set cookielocation.reload(true); //reload the page});
But it failed. Looked around and figured out that the .get ajax called might not be successful before the page reload. ajax is asynchronous, so the reload function could be executing during the ajax called.
The solution is using ajax callback to make sure reload function runs after ajax call ended, see the revise code as the following,
$('#btn').click(function(){$('#btn').html('Please wait ...');$.get("/ajax/update.php?action=set", function(){location.reload(true);});});
In a project, I need to write a php code to talk to informix database, which I have not done before.
First, you need PHP Informix Module, here is an guide, http://www.ibm.com/developerworks/data/library/techarticle/dm-0606bombardier/
Fortunately, the server I am working on has already installed this module, so I just wrote a simple test script as the following,
<?php$conn_id = ifx_connect ("mydb@ol_srv1", "user", "pass");?>
This code snippet is from PHP Manual, which is actually not a good for test. because if there is some error in ifx_connect, you will not see any error message. I found a better one from PhpDig.net, http://www.phpdig.net/ref/rn30re552.html
if (!$conn = @ifx_connect( "stores7@demo_se", "testuser", "password" )) {die( sprintf( "Connection error: %s %s", ifx_error(), ifx_errormsg() ) );}
I experienced the following error at the beginning,
Connection error: E [SQLSTATE=IX 001 SQLCODE=-1829] Unable to load locale categories.
The guy from IBM had an explanation http://www.iiug.org/forums/ids/index.cgi/noframes/read/3333
OK, some environment parameters missing, $INFORMIXDIR, after fixing this one, I got another one missing:
Connection error: E [SQLSTATE=IX 000 SQLCODE=-25560] Environment variable INFORMIXSERVER must be set.
Finally, fixed!
default_socket_timeout = 120
max_execution_time = 60
memory_limit = 20M
In soap client, connection_timeout is equivalent to default_socket_timeout.
<?php
$soapClient = new SoapClient('http://www.example.com/path/to.wsdl',
array('connection_timeout' => 120));
?>
Looks like soapclient use similar technique as file_get_contents() does
to get wsdl file. But unlike wget, file_get_contents generates distinct
packet for each line of HTTP request. Server doesn't reply on these
small chunks.
To let PHP behave like wget:
Define the following function:
function curl_file_get_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
And replace all file_get_contents entries with curl_file_get_contents.