Wednesday, November 29, 2023

PHP : Multi array search

function multi_array_search($array, $search)
    {
        $result = array();
        foreach ($array as $key => $value) {
            foreach ($search as $k => $v) {
                if (!isset($value[$k]) || $value[$k] != $v) {
                    continue 2;
                }
            }
            $result[] = $value;
        }
        return $result;
    }

 

How to use?

Exp; 

$array_result = array(array("id"=>1,"name"=>"Ayam"),array("id"=>1,"name"=>"Itik"));

multi_array_search($array_result, ["id" => 1]);

Result :

 array("id"=>1,"name"=>"Ayam")

PHP : result to select option item

function result_to_option($result_set=array(), $value_feild='', $label_field='', $selected_val='', $extra_attr=array(), $lbl_of_lbl='')
    {
        $_ci = get_instance();
        $option = '';
        // pr($selectd_val);
        if(!empty($result_set))
        foreach ($result_set as $key => $value) {
            $extr = '';
            if(count($extra_attr) > 0){
                foreach ($extra_attr as $extattr) {
                    $extr .= ' data-'.$extattr.'="'.@$value->$extattr.'"';
                }
            }
            $selected = '';
            if($selected_val == $value->$value_feild){
                $selected = ' selected="selected"';
            }
            if(is_array($label_field)){
                if(count($label_field) > 0){
                    $lbltext = array();
                    foreach ($label_field as $lblval) {
                        $lbltext[] = $value->$lblval;
                    }
                    $lbl = implode(' - ',array_filter($lbltext));
                }else{
                    $lbl = $value->$label_field;
                }
            }else{
                $lbl = $value->$label_field;
            }
            
            $option .= '<option value="'.$value->$value_feild.'" '.$extr.''.$selected.'>'.strtoupper(trim(preg_replace('/\s+/', ' ',$lbl_of_lbl.' '.$lbl))).'</option>'."\n";
        }
        return $option;
    }

PHP : result to array function

if (!function_exists('result_to_array')) {
    function result_to_array($result_set=array(), $value_feild='', $label_field='')
    {

        $_ci = get_instance();
        $option = [];
        foreach ((array)$result_set as $key => $value) {

            if(is_array($label_field)){
                if(count($label_field) > 0){
                    $lbltext = array();
                    foreach ($label_field as $lblval) {
                        $lbltext[] = $value->$lblval;
                    }
                    $lbl = implode(' - ',$lbltext);
                }else{
                    $lbl = $value->$label_field;
                }
            }else{
                $lbl = $value->$label_field;
            }
            
            $option[$value->$value_feild] = $lbl;
        }
        return $option;
    }
}

Monday, November 11, 2019

ios/iphone safari table header static with content scroll fix

We fix the problem with javascript.
1. You need to create normal table functioning on others browser.
2. Apply this solution below with cloning concept.

var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        },
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i);
        },
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        },
        Opera: function() {
            return navigator.userAgent.match(/Opera Mini/i);
        },
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
        }
    };

function iosTablesScroll(){
        return true;
        if(isMobile.iOS() && $('#table-wrapper').length){
            //create same scroll
            $("#table-wrapper").scroll(function(){
                $(".table-header").scrollLeft($(this).scrollLeft());
            });

            if($(".table-header:visible").length){
                $(".table-header").remove(); //reset before create
            }
            //create dummy table header
            var iostable = '
'+
                        '  '+
                        ' 
'+
                        '
';
            $("#content").before(iostable);
            $(".crypto-table thead").clone().appendTo('.table-header table');
            $('#table-wrapper').removeClass('full-height'); //reset

            //put same width td and th
            t1 = $("#table-wrapper table th");
            t2 = $("#table-wrapper table td");
            if(t2.html() != 'No stock at the moment') {
                t2.each(function (index) {
                          $(this).attr('width',t1.eq(index).attr('width'));
                });
            }

            $("table").css('table-layout','fixed');
            $(".table-header").show();
            $(".crypto-table thead").hide();
        }else{
            $(".table-header").hide();
            $(".crypto-table thead").show();
        }
    }

Friday, September 3, 2010

CSS hack, different browsers

Comprehensive List of Browser-Specific CSS Hacks

/***** Selector Hacks ******/

/* IE6 and below */
* html #uno { color: red }


/* IE7 */
*:first-child+html #dos { color: red }


/* IE7, FF, Saf, Opera */
html>body #tres { color: red }


/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }


/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }

/* Safari 2-3 */

html[xmlns*=""] body:last-child #seis { color: red }


/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }


/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho { color: red }


/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
#diez { color: red }
}


/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
#veintiseis { color: red }

}


/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece { color: red }


/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red }


/* Everything but IE6-8 */
:root *> #quince { color: red }


/* IE7 */
*+html #dieciocho { color: red }


/* Firefox only. 1+ */
#veinticuatro, x:-moz-any-link { color: red }


/* Firefox 3.0+ */
#veinticinco, x:-moz-any-link, x:default { color: red }




/***** Attribute Hacks ******/

/* IE6 */
#once { _color: blue }


/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }


/* Everything but IE6 */
#diecisiete { color/**/: blue }

/* IE6, IE7, IE8 */

#diecinueve { color: blue\9; }

/* IE7, IE8 */

#veinte { color/*\**/: blue\9; }

/* IE6, IE7 -- acts as an !important */

#veintesiete { color: blue !ie; } /* string after ! can be anything */


source : http://paulirish.com/2009/browser-specific-css-hacks/
Thanks to :Paul Irish. as my note

Friday, April 23, 2010

mysql a way to do - copy, insert, select,

Mysql PHP Insert multiple data in 1(one) query

<?

$sql = ' INSERT INTO tablename ( fieldA , fieldB ) VALUES ( dataA1 , dataB1 ), ( dataA2 , dataB2)';
$result = mysql_query($sql);

?>

Insert/copy data from other to another table

<?

$sql = ' INSERT INTO tableA SELECT * FROM tableB ';
$result = mysql_query($sql);

?>

CodeIgniter using controller for beginner

You must know that are

-config : Configuration files
-helper : helper for application, contain function that you create
-libraries : Collection of your code.
-errors : Contains template for error display
-hooks : Controlling files load.
-model : Collection of your code
-controller : Controller, control client request to others(view,library... etc)
-view : Template for showing information to user.



simple create test page

1. if your class name is thegreatestpost, you should save your controller file as thegreatestpost.php

<?php
class thegreatestpost extends Controller {

function index()
{
echo 'Hello the greatest post!';
}
}
?>


to view it, www.your-site.com/index.php/thegreatestpost/


if you want controller thegreatestpost is default controller, just edit $route['default_controller'] in config\routes.php as :
$route['default_controller'] = 'thegreatestpost';
and url to view index is www.your-site.com/index.php/

display result will be:
Hello the greatest post!

Add another function,

<?php
class thegreatestpost extends Controller {

function index()
{
echo 'Hello the greatest post!';
}
function greatest()
{
echo 'Hello postmen';
}

}
?>


to view greatest www.your-site.com/index.php/thegreatestpost/greatest/
result view:
Hello postmen

to passing value url to your function simply like this:

function greatest($value1 = "") : url= www.your-site.com/index.php/thegreatestpost/greatest/123

meaning $value1 = 123

function greatest($value1 = "", $value2 = "") :url= www.your-site.com/index.php/thegreatestpost/greatest/123/abc

meaning $value1 = 123, $value2 = abc


more reference visit : http://codeigniter.com/