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/

Monday, March 22, 2010

Hide iframe border on IE

<html>
<head>
<body bgcolor="#000000">
</head>
<iframe src="./index.html" frameborder="0" border="0" cellspacing="0" width="100%" marginwidth="0" marginheight="0" height="75%">
</iframe>
<br><br>
<iframe src="./ads.html" noresize="noresize" frameborder="0" border="0" cellspacing="0" scrolling="no" width="100%" marginwidth="0" marginheight="0" height="25%">
</iframe>
</body>
</html>

Thursday, March 18, 2010

jQuery Manual/documentation

jQuery Manual/documentation 1.4 version in .chm format for download
This is jQuery script manual that I found over the internet. I share and you will be able to develop your web with jQuery that contain jQuery API and documentation . Click the jQuery logo to download.






Thanks to http://charupload.wordpress.com and http://jquery.com/

What is jQuery used for




jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

You may use jQuery under the terms of either the MIT License or the Gnu General Public License (GPL) Version 2.

embedding jquery-1.4.2.min.js or jquery-1.4.2.js or both of them into your code, you can manipulate or using futures of jQuery. You do not need to write a thousand line of javascript code but just include js file into your code. You can used the futures such as CSS,Effect,Ajax,manipulation, and others greatest java

How to get started?? just visit http://docs.jquery.com/Main_Page.

Click HERE to download jquery manual documentation

Wednesday, March 17, 2010

CSS style like print preview / paper view

Need to preview like print preview? use this css style example.


<html>
<head>
<title>Contoh Kandungan</title>

<style type="text/css">
body {
background-color: #9099ae;
}
.textclass {

background-color: #fff;
margin: 0 auto;
border:1px solid #000;
border-right-width: 3px;
border-bottom-width:3px;
padding: 5em 6em;
font-family: Arial;
}

</style>

</head>
<body>
<p class="textclass">
Welcome to thegreatestpost.blogspot.com
<br>
Insert your content here.
</p>
</body>
</html>


sample:





Friday, March 12, 2010

Create CHM file / Help file

Usually manual or help file are created in .pdf (Portable Document Format) format or .chm (Microsoft Compiled HTML Help files) format. If it's compared both of them, chm format more user friendly but it's just for windows.

There are many software to create chm file and one of them is Abee Chm Maker by AbeeTech, http://abeetech.com/

It's free software and you can download it at http://abeetech.com/






visit abeetech

Monday, March 1, 2010

Send SMS function using PHP

What are usually need to make a sms;



This is a simple function to send sms using php script.


<?php

function PostToHostSMS($host, $port, $username, $password, $data_to_send)
{
$dc = 0;
$bo ="--------453534534534536";

$fp = fsockopen($host, $port, $errno, $errstr);
if (!$fp) {
echo "errno: $errno \n";
echo "errstr: $errstr\n";
return $result;
}

fputs
($fp, "POST / HTTP/1.1\r\n");
if ($username != "") {
$auth = $username . ":" . $password;
echo "auth: $auth\n";
$auth = base64_encode($auth);
echo "auth: $auth\n";
fwrite
($fp, "Authorization: Basic " . $auth . "\r\n");
}
fputs
($fp, "User-Agent: NowSMS PHP Script\r\n");
fputs
($fp, "Accept: */*\r\n");
fputs
($fp, "Content-type: multipart/form-data; boundary=$bo\r\n");

foreach($data_to_send as $key=>$val) {
$ds =sprintf("%s\r\nContent-Disposition: form-data;
name=\"%s\"\r\n%s\r\n"
,$bo,$key,$val);
$dc += strlen($ds);

}
$dc += strlen($bo)+3;
fputs
($fp, "Content-length: $dc\r\n");
fputs
($fp, "\r\n");
fputs
($fp, "This is a MIME message\r\n\r\n");

foreach($data_to_send as $key=>$val) {
$ds =sprintf("%s\r\nContent-Disposition: form-data;
name=\"%s\"\r\n%s\r\n"
,$bo,$key,$val);
fputs
($fp, $ds );
}
$ds = $bo."--\r\n" ;
fputs
($fp, $ds);

$res = "";

while(!feof($fp)) {
$res .= fread($fp,1);
}
fclose
($fp);


return $res;
}

?>


Create xml rss feed with PHP

First, write a script like below;

<?php header('Content-type: text/xml'); ?>

<?php $phpver = phpversion(); ?>

<rss version="2.0">
<channel>
<title>SapuraTIE</title>
<description>Sapuratie</description>
<language>en-US</language>
<link>http://thegreatestpost.blogspot.com/</link>
<copyright>Your copyright</copyright>
<generator>
XML/RSS feed generator by thegreatestpost(PHP version
<?php echo $phpver; ?>)
</generator>

<managingEditor>Site Editor</managingEditor>
<webMaster>Webmaster Email</webMaster>



<?php
require_once('db_connect.php'); //your connection to database

$query = "SELECT id,content_title,content_data,content_date,
content_page FROM sapurastie_article
WHERE content_section <> 10 AND
content_language =
$lang ORDER BY content_date DESC LIMIT 0,15"; //your query
$execute = mysql_query($query) or die(mysql_error());

while($result = mysql_fetch_array($execute)) {
?>
//Start create item
<item>
<title> <?=htmlentities(strip_tags($result['content_title'])); ?></title>
<description>
<?=htmlentities(strip_tags(substr($result['content_data'],0,500)."...",'ENT_QUOTES'));
?>

</description>

<pubDate>
<?php
echo date('r', strtotime($result['content_date'])); ?>
</pubDate>
<guid>http://thegreatestpost.blogspot.com</guid>
</item>
<?php } ?>

</channel>
</rss>

then, the output will be like;



Created by: thegreatestpost.



Thursday, February 18, 2010

Entering P1 WiMax Modem - web login (Dekstop Modem With WiFi Plan)

P1 is one of Internet Service Provider in Malaysia without wire(wireless) - wireless 4G Broadband.

If you have no P1 get it now... :) visit : http://www.p1.com.my.
Picture below is my P1 Desktop Modem with WiFi for RM 49 per month for very basic plan. But it's nice for a blogger.


Let we go.. how to go inside modem UI. A simple address just open your web browser then go to this url http://10.1.1.254/ and enter the password and username.

Default password
Username : admin
Password : admin123
Note:  you can change this default password after web login account

Friday, February 12, 2010

List of web text editor - Open Source(free) and Commercial

These are three the best and free text editor for web. They are LGPL license for web application development.










Xinha    


 









More reference visit :  http://www.geniisoft.com/showcase.nsf/WebEditors

Add text-to-speech to your page.

vozMe
Wordpress plugin
Template for Blogger
Joomla



" Text to Voice speech "

If you want your article or text content convert to voice speech, just simply add vozMe to your page using this method. vozMe can translate your text to voice speech when click on the link or the icon depending on your setup option. There are many type of installation option for web page platform.

Here is example of vozMe:


Capture from http://www.uthm.edu.my.








Once you click the link to play, popup will appear like this :

You will enable to download the sound in mp3 format.











How to use..??
I was apply to this blog using embedding the script. What you need to do is select the text that want to speech, the click speech button. that's it.

1 select text:







2. Click speech button



To install to your page just visit vozME
There are manual and tutorial to add this.



Sharing tech. by thegreatestpost.
Thanks to : VozME - http://vozme.com/

Islamic Calendar script - Hijrah/Masihi Calendar converter

Copy this script and paste to your code to add the Islamic Calendar converter

<HTML>
<HEAD>
<SCRIPT language=JavaScript>

function intPart(floatNum){
if (floatNum< -0.0000001){
return Math.ceil(floatNum-0.0000001)
}
return Math.floor(floatNum+0.0000001)
}
function weekDay(wdn){
if(wdn==0){
return "Monday"
}
if(wdn==1){
return "Tuesday"
}
if(wdn==2){
return "Wednesday"
}
if(wdn==3){
return "Thursday"
}
if(wdn==4){
return "Friday"
}
if(wdn==5){
return "Saturday"
}
if(wdn==6){
return "Sunday"
}
return ""

}
function chrToIsl(arg) {
d=parseInt(arg.CDay.value)
m=parseInt(arg.CMonth.value)
y=parseInt(arg.CYear.value)
if ((y>1582)||((y==1582)&&(m>10))||((y==1582)&&(m==10)&&(d>14)))
{
jd=intPart((1461*(y+4800+intPart((m-14)/12)))/4)+intPart((367*(m-2-12*(intPart((m-14)/12))))/12)-
intPart( (3* (intPart( (y+4900+ intPart( (m-14)/12) )/100) ) ) /4)+d-32075
}
else
{
jd = 367*y-intPart((7*(y+5001+intPart((m-9)/7)))/4)+intPart((275*m)/9)+d+1729777
}
arg.JD.value=jd
arg.wd.value=weekDay(jd%7)
l=jd-1948440+10632
n=intPart((l-1)/10631)
l=l-10631*n+354
j=(intPart((10985-l)/5316))*(intPart((50*l)/17719))+(intPart(l/5670))*(intPart((43*l)/15238))
l=l-(intPart((30-j)/15))*(intPart((17719*j)/50))-(intPart(j/16))*(intPart((15238*j)/43))+29
m=intPart((24*l)/709)
d=l-intPart((709*m)/24)
y=30*n+j-30

arg.HDay.value=d
arg.HMonth.value=m
arg.HYear.value=y
}
function islToChr(arg) {
d=parseInt(arg.HDay.value)
m=parseInt(arg.HMonth.value)
y=parseInt(arg.HYear.value)
jd=intPart((11*y+3)/30)+354*y+30*m-intPart((m-1)/2)+d+1948440-385
arg.JD.value=jd
arg.wd.value=weekDay(jd%7)
if (jd> 2299160 )
{
l=jd+68569
n=intPart((4*l)/146097)
l=l-intPart((146097*n+3)/4)
i=intPart((4000*(l+1))/1461001)
l=l-intPart((1461*i)/4)+31
j=intPart((80*l)/2447)
d=l-intPart((2447*j)/80)
l=intPart(j/11)
m=j+2-12*l
y=100*(n-49)+i+l
}
else
{
j=jd+1402
k=intPart((j-1)/1461)
l=j-1461*k
n=intPart((l-1)/365)-intPart(l/1461)
i=l-365*n+30
j=intPart((80*i)/2447)
d=i-intPart((2447*j)/80)
i=intPart(j/11)
m=j+2-12*i
y=4*k+n+i-4716
}

arg.CDay.value=d
arg.CMonth.value=m
arg.CYear.value=y

}
</SCRIPT>
<head>

<BODY>
<TABLE border=1>
<TBODY>
<TR>
<TH></TH>
<TH>Day</TH>
<TH>Month</TH>
<TH>Year</TH></TR>
<TR>
<TH>Masehi </TH>
<FORM name=IrgendÃ…¡ppis>
<TH><INPUT size=4 value=1 name=CDay></TH>
<TH><INPUT size=4 value=1 name=CMonth></TH>
<TH><INPUT size=4 value=1996 name=CYear></TH></TR>
<TR>
<TH>Hijrah</TH>
<TH><INPUT size=4 name=HDay></TH>
<TH><INPUT size=4 name=HMonth></TH>
<TH><INPUT size=4 name=HYear></TH></TR></TBODY></TABLE>
<P>
<INPUT onclick=chrToIsl(this.form) type=button value="Masehi to Hijrah" name=CtoH>
<INPUT onclick=islToChr(this.form) type=button value="Hijrah to Masehi" name=HtoC>
<P>Day of the week: <INPUT size=10 name=wd>
<P>Julian Day: <INPUT size=7 name=JD>
<P></FORM>
<HR>
<p><font color="#006600" size="1" face="Century Gothic">Julian dates assign a unique number to each
calendar day. The Julian day number counts the number of days since noon
on January 1, -4712 (astronomical calendar) or January 1, 4713 BC (civil
calendar). This system, widely used by astronomers, was proposed by Julius
J. Scaliger in 1583. Hours and minutes are counted as fractions of a day
since the last noon (Universal Time).</font></p>
<TABLE border=1>
<TBODY>
<TR>
<TH>1</TH>
<TH>Muharram</TH>
<TH></TH>
<TH>7</TH>
<TH>Rajab</TH></TR>
<TR>
<TH>2</TH>
<TH>Safar</TH>
<TH></TH>
<TH>8</TH>
<TH>Sha'ban</TH></TR>
<TR>
<TH>3</TH>
<TH>Rabi'ul Awal</TH>
<TH></TH>
<TH>9</TH>
<TH>Ramadhan</TH>
</TR>
<TR>
<TH>4</TH>
<TH>Rabi'ul Akhir</TH>
<TH></TH>
<TH>10</TH>
<TH>Shawwal</TH></TR>
<TR>
<TH>5</TH>
<TH>Jumadil Awal</TH>
<TH></TH>
<TH>11</TH>
<TH>Zulkaedah</TH>
</TR>
<TR>
<TH>6</TH>
<TH>Jumadil Akhir</TH>
<TH></TH>
<TH>12</TH>
<TH>Zulhijjah</TH>
</TR></TBODY></TABLE>
</BODY>
</HTML>


source: over the internet