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>