Friday, July 16, 2010

PHP Display array pre print_r into list button ul li

Related
Display array in list (collapsable)
Display array in print_r
Display array in ul li
Display array in pre

Usually in programming, when you debugging an array you will be using the pre and print_r
This is all right when the data is small. But if the array size is very large things will be hard which is happen to me lately.

So I create a function that display the array on the list. Plus this list is collapsible and it is a very simple code. Only 2 function needed

function thejavascriptrewrite()
{
echo "<script type='text/javascript'>";

echo "
function switchme( \$theId)
{
\$theElement = document.getElementById(\$theId);

if( \$theElement.style.display == 'none'){
\$theElement.style.display = '';
}
else{
\$theElement.style.display = 'none';
}

}
";

echo "</script>";
}

function arraytolist( $data, $iteration = 0, $fortheUL = null)
{
$idName = "someCounterId";

echo "<ul $fortheUL>";

foreach( $data as $key => $value)
{
if( !is_array($value)){
echo "<li>";
echo "[$key]=".$value;
echo "</li>";
}
else{

$iteration++;
$totalArray = count( $value);

echo "<li>"."<a onclick=\"switchme('$idName".$iteration."')\">$key ($totalArray)</a>";
$forNextUL = "id='$idName".$iteration."' style='display: none;'";
$iteration = arraytolist($value, $iteration, $forNextUL);
echo "</li>";
}
}

echo "</ul>";
return $iteration;
}

How to use?

paste this code

$data = array( 'abc', 'def', 'ghi');
thejavascriptrewrite();
arraytolist($data);

Tuesday, July 13, 2010

Jquery from Novice to Ninja

Sitepoint offer free Ebook "Jquery from Novice to Ninja" when Spain win the World Cup and I downloaded the Ebook (9MB) for free!

Saturday, July 3, 2010

HTML CSS Change Paragraph Spacing

I do some google to change my website design to change paragraph spacing and come across to this page. Its show the link that related to it

The site is http://answers.google.com/answers/threadview/id/783141.html

While the reference website is
  • http://lab.artlung.com/change-space-between-paragraphs/
  • http://www.w3schools.com/css/css_margin.asp
  • http://www.westciv.com/style_master/academy/css_tutorial/properties/margin.html

All the link given is suggesting you to using css margin.
As for me, by using this already enough
<p style="line-height: 200px;">Hello World</p>

Friday, June 11, 2010

Display and Disable Super hidden file

Yuu all know most of virus is hidden and the most typical way for them to infect you PC was through portable media like pen drive or portable harddisk.
I got alot of this case when I put my portable HDD to my friend. Luckyly I got antivirus to detect them but not to remove them.

The problem is the virus file is hidden and its not just typical hidden. Its a 'Super hidden file' where your 'Tool > Folder option > Show hidden file and folder' wont help at all.
So to encounter this you must use the command line aka cmd

So, type 'cmd' at run.

Navigate the 'cmd' into the portable media. In my case is typing 'I:' which direct me into I:\>



After that type 'dir /ah' and I see the virus! which is rfg.exe and his buddy autorun.inf.



The problem is I can see it in cmd but cant see in normal view.
So I disable their 'super hidden' using cmd by typing
'attrib -s -h -r rfg.exe' and 'attrib -s -h -r autorun.inf'

After typing these 2 things and It shows. So I delete them.

Just for friendly reminder. Never double click portable media. Right click and 'Explore' is the easy safest way.

Thats it, hope its usefull

*note
I just encounter another virus in my PenDrive but this method does not work
So this tutorial is not going to 100% solve your problem

Friday, June 4, 2010

Rounded border

After several research.
Here is the thing that is needed to create rounded rectangle.
This works on FF and GC. Not on IE and dont know on others

-moz-border-radius: 20px 20px 20px 20px; background: none repeat scroll 0 0 #D8DEEF;
border-bottom-left-radius: 20px 20px;
border-bottom-right-radius: 20px 20px;
border-top-left-radius: 20px 20px;
border-top-right-radius: 20px 20px;

Sunday, May 23, 2010

Playing with date

Since I easily forget about MySQL date function. I wrote this to myself.

I have a field name `created` with DATETIME format like 2010-05-24 11:24:05

Using the MySQL function
SELECT NOW() give you the latest time like 2010-05-24 11:24:05

SELECT CURDATE() give you the current date like 2010-05-24

So I available command is. Lets say the current time is 2010-05-24 11:24:05
SELECT YEAR( NOW()); will return 2010
SELECT MONTH( NOW()); will return 05
SELECT DAY( NOW()); will return 24
SELECT TIME( NOW()); will return 11:24:05
SELECT HOUR( NOW()); will return 11
SELECT MINUTE( NOW()); will return 24
SELECT SECOND( NOW()); will return 05

*Note
SELECT YEAR('2010-05-24 11:24:05'); will also return 2010


To select a record in the same month
SELECT * FROM table WHERE YEAR(`created`) = YEAR(CURDATE()) AND MONTH(`created`) = MONTH(CURDATE())

Another format is like this
SELECT name, created FROM customer
WHERE created BETWEEN '2010-01-04 00:00:00' AND '2010-01-06 00:00:00';

*Take note the field registerdate format is DATETIME()
*Take note that the date range in the between must be from low to high

These is a function to take the 'current amount from stock forecast'. Let say with these situation
15 March 2011, Gold price will be 2.0
20 March 2011, Gold price will be 2.1
30 March 2011, Gold price will be 2.2

Today is 25 March 2011. So the SQL will return "Gold price will be 2.1"
So these is the SQL
"SELECT `goldprice` FROM `vtiger_goldforecast` WHERE `datestart` <=CURDATE() ORDER BY `vtiger_goldforecast`.`datestart` DESC LIMIT 1";



Update 1.2 (25 Nov 2011) - Select a record within a date
Case: The table has start date and end date. You want to retrieve a record where today is still withing the start and end date

SELECT * FROM special eventWHERE NOW( ) BETWEEN startdate AND enddate


Thats for today, version 1.1
Going to update later

Saturday, May 22, 2010

Javascript get screen browser size resolution

You might find it everywhere but I just keep this link for my own reference.
Normally it would be like this
screen.height
screen.width

*There is a difference using screen with the link given

But this tutorial is more focus on Window size and scrolling
http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

Creating a popup
http://www.blazonry.com/javascript/windows.php


As for concolusion. I create a popup handle


//Create a popup
function popup( link, senderId)
{
//Get the browser resolution
var width = getBrowserWidth();
var height = getBrowserHeight();

//alert( width + "=" + height + " - " + screen.width + "=" + screen.height);

//Reduce the screen by 20%
width = width * 0.8;
height = height * 0.8;

//Put the popup at the middle of the page
var left = (screen.width/2)-(width/2);
var top = (screen.height/2)-(height/2);

//alert(senderId);

popupWindow = window.open( link, "popupWindow", "width="+width+",height="+height+",top="+top+",left="+left+",scrollbars=yes,toolbar=no,location=no,menubar=no,resizable=no,directories=no");
popupWindow.focus();
}


//Change the innerHTML based on the given Id
function changeInnerHTML( elementName, theValue)
{
var theElement = window.opener.document.getElementById(elementName);
theElement.innerHTML = theValue;
}


//Change the value based on the given Id
function changeValue( elementName, theValue)
{
var theElement = window.opener.document.getElementById(elementName);
theElement.value = theValue;
}


//Get the browser width
function getBrowserWidth()
{
var myWidth = 0;

if( typeof( window.innerWidth ) == 'number' ) {
myWidth = window.innerWidth; //Non-IE
}
else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
myWidth = document.documentElement.clientWidth; //IE 6+ in 'standards compliant mode'
}
else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
myWidth = document.body.clientWidth; //IE 4 compatible
}

return myWidth;
}


//Get the browser height
function getBrowserHeight()
{
var myHeight = 0;

if( typeof( window.innerWidth ) == 'number' ) {
myHeight = window.innerHeight; //Non-IE
}
else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
myHeight = document.documentElement.clientHeight; //IE 6+ in 'standards compliant mode'
}
else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
myHeight = document.body.clientHeight; //IE 4 compatible
}

return myHeight;
}



Found out problem
1. Not really 'at center' if the browser zoom is not 100% (happen on FF as I found it out)

Want to use this code? its free and 'as is'