Posts

Showing posts from July, 2015

Add 1 month from today in php

$endOfCycle=date('Y-m-d', strtotime("+30 days"));or try this:
$endOfCycle = date("Y-m", time()+2592000); this adds 30 days, not exactly a month tough.

Create helper in codeigniter

A CodeIgniter helper is a PHP file with multiple functions. It is not a class
Create a file and put the following code into it.
<?php if(!defined('BASEPATH'))exit('No direct script access allowed');if(! function_exists('test_method')){function test_method($var =''){return $var;}} Save this to application/helpers/ . We shall call it "new_helper.php"
The first line exists to make sure the file cannot be included and ran from outside the CodeIgniter scope. Everything after this is self explanatory.

Using the Helper
This can be in your controller, model or view (not preferable)
$this->load->helper('new_helper'); echo test_method('Hello World'); If you use this helper in a lot of locations you can have it load automatically by adding it to the autoload configuration file.
$autoload['helper']= array('new_helper');

Select records from today, this week, this month php mysql

Assuming your date column is an actual MySQL date column:
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY score DESC; SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 WEEK) ORDER BY score DESC; SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 MONTH) ORDER BY score DESC;OR Current month:
SELECT * FROM jokes WHERE YEAR(date)= YEAR(NOW()) AND MONTH(date)=MONTH(NOW()); Current week:
SELECT * FROM jokes WHERE WEEKOFYEAR(date)= WEEKOFYEAR(NOW()); Current day:
SELECT * FROM jokes WHERE YEAR(date)= YEAR(NOW()) AND MONTH(date)= MONTH(NOW()) AND DAY(date)= DAY(NOW());

Delete all numbers after point in PHP

floor() will round a number down to the nearest integer.
OR
Using the explicit cast to (int) is the most efficient way to to this AFAIK. Also casting to (int) will cut off the digits after the "." if the number is negative instead of rounding to the next lower negative number:
echo (int)(-3.75);//echoes "-3"; echo floor(-3.75);//echoes "-4";

Stop Paypal recurring payment from paypal

Cancelling a subscription cancels all future scheduled payments of that subscription. A subscription can be cancelled up until three business days before the next scheduled payment.
1.Log in to your PayPal account.
2.Click Profile near the top of the page.
3.Click My money.
4.Click Update beside 'My pre-approved payments.'
5.Click the name of the subscription you wish to cancel.
6.Click Cancel.
this is from paypal documentation find it here

codeigniter active record left join

$this->db->select('email'); $this->db->from('emails');$this->db->where('user_id', $userid);$this->db->join('user_email','user_email.user_id = emails.id','left');$query = $this->db->get();

How to add favicon in website?

Image
A favicon is a graphic image associated with a particular Webpage and/or Website.  Now the question comes, how to add a favicon to my website/webpage? To begin with, you will need a small icon that you wish to set as the ‘FavIcon’. It should be 16×16 in size. Once you have the icon ready, rename it tofavicon.ico and upload it to your Server root folder, using Contribute through the option File-> Publish File from my Computer. Alternatively, you can use the below code between the <head></head> (x)HTML tags to set the favicon even though the .ico file in placed in different location. <link rel="icon" type="image/ico" href="http://www.mysite.com/favicon.ico"/>

Check Image Height and Width using jQuery

<form action="/" method="post">
<input type="file" id="fileUpload" />
<input id="upload" type="button" value="Upload" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
    $("#upload").bind("click", function () {
        //Get reference of FileUpload.
        var fileUpload = $("#fileUpload")[0];

        //Check whether the file is valid Image.
        var regex = new RegExp("([a-zA-Z0-9\s_\\.\-:])+(.jpg|.png|.gif)$");
        if (regex.test(fileUpload.value.toLowerCase())) {

            //Check whether HTML5 is supported.
            if (typeof (fileUpload.files) != "undefined") {
                //Initiate the FileReader object.
                var reader = new FileReader();

                //Read the cont…

Datetime equal or greater than today in MySQL

SELECT*FROM users WHERE created >= CURDATE();orSELECT*FROM myTable WHERE DATE(myDate)= DATE(NOW())

Get both array value and array key in PHP

foreach($yourArray as $key => $value){//do something with your $key and $value; echo '<a href="'. $value .'">'. $key .'</a>';} Edit: As per Capsule's comment - changed to single quotes.