Skip to content

Instantly share code, notes, and snippets.

View INDIAN2020's full-sized avatar

Gogula Sivannarayana INDIAN2020

View GitHub Profile
@INDIAN2020
INDIAN2020 / gist:5610801
Created May 20, 2013 07:04
php: count days
function daysCount($date)
{
$diff = (strtotime( date('Y-m-d') ) - strtotime($date)) / 86400;
return $diff;
}
@INDIAN2020
INDIAN2020 / gist:5626847
Created May 22, 2013 11:20
pdo: lastinsertId
if( $sql_statement->execute() ) {
$this->db_connect->lastInsertId();
if( $sql_statement->rowCount() > 0 ) {
$this->previousid = $this->db_connect->lastInsertId('showdate');
var_dump($this->previousid);
} else {
// no record inserted, therefore error condition exists
echo "No record inserted. Cannot proceed.";
$error = TRUE;
}
@INDIAN2020
INDIAN2020 / gist:5635446
Created May 23, 2013 11:32
php: unset session variable
unset($_SESSION['session_var']);
@INDIAN2020
INDIAN2020 / gist:5635800
Created May 23, 2013 12:47
sql: trigger list on mysql
Get list of existing TRIGGERs in MYSQL
While MySQL has features like StoredProcedure and View, it doesn't have any option for displaying TRIGGER list in the 'Schemata' tab (right) section of QueryBrowser.
Generally, we need a third party control like MySQL Workbench to get the list of existing TRIGGER lists.But there is another way through which we can get existing trigger lists and that is from the Metadata(Data about data).
To get all the trigger list irrespective of the database name:
SELECT * FROM information_schema.TRIGGERS;
To get list of trigger against a specific database:
SELECT * FROM information_schema.TRIGGERS WHERE TRIGGER_SCHEMA='database_name';
@INDIAN2020
INDIAN2020 / gist:5635944
Created May 23, 2013 13:10
sql: datahandler in pdo
if(!$sql_statement->execute()) {
return false;
}
$sql_count = $sql_statement->rowCount();
if($sql_count > 0) {
return true;
}else {
return false;
}
@INDIAN2020
INDIAN2020 / gist:5648632
Created May 25, 2013 10:31
php: checkbox value validation
if (!empty($_POST)) {
if (!empty($_POST['save'])) {
$active = isset($_POST['showcancelled']) && $_POST['showcancelled'] ? "1" : "0";
if ($active == 1) {
echo "Checked";
} else {
echo "fail";
}
@INDIAN2020
INDIAN2020 / index.php
Created May 26, 2013 15:26
php: helperfunctions
<?php
class HelperFunctions
{
/**
* This function is responsible to convert % to double
* @param integer $a
* @return double
*/
public static function isPercentage($a){
if(preg_match('/%/',$a)){
@INDIAN2020
INDIAN2020 / gist:5654895
Created May 27, 2013 02:31
php: helperfunctions
<?php
class HelperFunctions
{
/**
* This function is responsible to convert % to double
* @param integer $a
* @return double
*/
public static function isPercentage($a){
if(preg_match('/%/',$a)){
@INDIAN2020
INDIAN2020 / gist:5756549
Created June 11, 2013 12:51
wordpress: search short code
<?php
//add_shortcode('wpbsearch', 'get_search_form');
function wpbsearchform( $form ) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
</div>
</form>';
@INDIAN2020
INDIAN2020 / gist:5804882
Created June 18, 2013 12:15
media queries standard devices
/* Smartphones (portrait and landscape) -----------*/
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) -----------*/
@media only screen and (min-width : 321px) {
/* Styles */
}