Friday, November 11, 2016
Thursday, November 10, 2016
Tuesday, February 16, 2016
Anjala - Kanjadai Video | Vimal, Nandhita | Gopi Sundar
Anjala - Kanjadai Video | Vimal, Nandhita | Gopi Sundar
Thursday, September 6, 2012
Array pagination
function pagination_array($array, $page = 1, $link_prefix = false, $link_suffix = false, $limit_page = 12, $limit_number = 10)
{
if (empty($page) or !$limit_page) $page = 1;
$num_rows = count($array);
if (!$num_rows or $limit_page >= $num_rows) return false;
$num_pages = ceil($num_rows / $limit_page);
$page_offset = ($page - 1) * $limit_page;
//Calculating the first number to show.
/*if ($limit_number)
{
$limit_number_start = $page - ceil($limit_number / 2);
$limit_number_end = ceil($page + $limit_number / 2) - 1;
if ($limit_number_start < 1) $limit_number_start = 1;
//In case if the current page is at the beginning.
$dif = ($limit_number_end - $limit_number_start);
if ($dif < $limit_number) $limit_number_end = $limit_number_end + ($limit_number - ($dif + 1));
if ($limit_number_end > $num_pages) $limit_number_end = $num_pages;
//In case if the current page is at the ending.
$dif = ($limit_number_end - $limit_number_start);
if ($limit_number_start < 1) $limit_number_start = 1;
}
else
{
$limit_number_start = 1;
$limit_number_end = $num_pages;
}
*/
//Generating page links.
/* for ($i = $limit_number_start; $i <= $limit_number_end; $i++)
{
$page_cur = "$i";
if ($page == $i) $page_cur = "$i";
else $page_cur = "$i";
$panel .= " $page_cur";
}
*/
/*
$panel = trim($panel);
//Navigation arrows.
if ($limit_number_start > 1) $panel = "<< < $panel";
if ($limit_number_end < $num_pages) $panel = "$panel > >>";
$output['panel'] = $panel; //Panel HTML source.
$output['offset'] = $page_offset; //Current page number.
$output['limit'] = $limit_page; //Number of resuts per page.
*/
$output['array'] = array_slice($array, $page_offset, $limit_page, true); //Array of current page results.
return $output;
}
{
if (empty($page) or !$limit_page) $page = 1;
$num_rows = count($array);
if (!$num_rows or $limit_page >= $num_rows) return false;
$num_pages = ceil($num_rows / $limit_page);
$page_offset = ($page - 1) * $limit_page;
//Calculating the first number to show.
/*if ($limit_number)
{
$limit_number_start = $page - ceil($limit_number / 2);
$limit_number_end = ceil($page + $limit_number / 2) - 1;
if ($limit_number_start < 1) $limit_number_start = 1;
//In case if the current page is at the beginning.
$dif = ($limit_number_end - $limit_number_start);
if ($dif < $limit_number) $limit_number_end = $limit_number_end + ($limit_number - ($dif + 1));
if ($limit_number_end > $num_pages) $limit_number_end = $num_pages;
//In case if the current page is at the ending.
$dif = ($limit_number_end - $limit_number_start);
if ($limit_number_start < 1) $limit_number_start = 1;
}
else
{
$limit_number_start = 1;
$limit_number_end = $num_pages;
}
*/
//Generating page links.
/* for ($i = $limit_number_start; $i <= $limit_number_end; $i++)
{
$page_cur = "$i";
if ($page == $i) $page_cur = "$i";
else $page_cur = "$i";
$panel .= " $page_cur";
}
*/
/*
$panel = trim($panel);
//Navigation arrows.
if ($limit_number_start > 1) $panel = "<< < $panel";
if ($limit_number_end < $num_pages) $panel = "$panel > >>";
$output['panel'] = $panel; //Panel HTML source.
$output['offset'] = $page_offset; //Current page number.
$output['limit'] = $limit_page; //Number of resuts per page.
*/
$output['array'] = array_slice($array, $page_offset, $limit_page, true); //Array of current page results.
return $output;
}
UTF8 Wordwrap
header("Content-Type: text/html; charset=UTF-8");
function wordwrap_utf8($str, $len)
{
preg_match_all('/[\xE0-\xFF][\x80-\xFF]{2}|./', $str, $match);
$finalStr = ' ';
$m = $match[0];
$ret = array();
$Total_Length = count($match[0]);
$flag1 = 1;
$flag2 = true;
for($j=0; $j < $Total_Length; $j++)
{
$ret[] = $m[$j];
if( $flag1 == $len )
{
$finalStr .= join('', $ret)."
";
$ret = array();
$flag1 = 1;
$flag2 = false;
}
else if( ( $j == $Total_Length-1 ) && ( $flag2 ) )
{
$finalStr .= join('', $ret)."
";
}
else
{
$flag1 = $flag1+1;
$flag2 = true;
}
}
return $finalStr;
}
$str ="aaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffddddddddddddd";
$str = 'ㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹ';
$width = 10;
$test1 = wordwrap_utf8($str, $width);
echo $test1;
?>
function wordwrap_utf8($str, $len)
{
preg_match_all('/[\xE0-\xFF][\x80-\xFF]{2}|./', $str, $match);
$finalStr = ' ';
$m = $match[0];
$ret = array();
$Total_Length = count($match[0]);
$flag1 = 1;
$flag2 = true;
for($j=0; $j < $Total_Length; $j++)
{
$ret[] = $m[$j];
if( $flag1 == $len )
{
$finalStr .= join('', $ret)."
";
$ret = array();
$flag1 = 1;
$flag2 = false;
}
else if( ( $j == $Total_Length-1 ) && ( $flag2 ) )
{
$finalStr .= join('', $ret)."
";
}
else
{
$flag1 = $flag1+1;
$flag2 = true;
}
}
return $finalStr;
}
$str ="aaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffdddddddddddddaaaaaaaadsfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdsfghgfhgggggggggggggffffffffffffffddddddddddddd";
$str = 'ㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹㄹ';
$width = 10;
$test1 = wordwrap_utf8($str, $width);
echo $test1;
?>
UTF8 String Split
function strcut_utf8($str, $len, $checkmb=false, $tail='')
{
/**
* UTF-8 Format
* 0xxxxxxx = ASCII, 110xxxxx 10xxxxxx or 1110xxxx 10xxxxxx 10xxxxxx
* latin, greek, cyrillic, coptic, armenian, hebrew, arab characters consist of 2bytes
* BMP(Basic Mulitilingual Plane) including Hangul, Japanese consist of 3bytes
**/
$html_decimalcodes = array("​","◀");
preg_match_all('/[\xE0-\xFF][\x80-\xFF]{2}|./', $str, $match); // target for BMP
$m = $match[0];
$slen = strlen($str); // length of source string
$tlen = strlen($tail); // length of tail string
$mlen = count($m); // length of matched characters
if ($slen <= $len)
{
/*echo $str;
echo '
';*/
$str = str_replace($html_decimalcodes,"", $str);
/*echo $str;
echo '
';*/
return $str;
}
if (!$checkmb && $mlen <= $len)
{
/*echo $str;
echo '
';*/
$str = str_replace($html_decimalcodes,"", $str);
/*echo $str;
echo '
';*/
return $str;
}
$ret = array();
$count = 0;
for($i=0; $i < $len; $i++) {
$count += ($checkmb && strlen($m[$i]) > 1)?2:1;
if($count + $tlen > $len) break;
$ret[] = $m[$i];
}
$text = html_entity_decode(join('', $ret).$tail);
/*echo $text;
echo '
';*/
$text = str_replace($html_decimalcodes,"", $text);
/*echo $text;
echo '
';*/
return $text;
}
{
/**
* UTF-8 Format
* 0xxxxxxx = ASCII, 110xxxxx 10xxxxxx or 1110xxxx 10xxxxxx 10xxxxxx
* latin, greek, cyrillic, coptic, armenian, hebrew, arab characters consist of 2bytes
* BMP(Basic Mulitilingual Plane) including Hangul, Japanese consist of 3bytes
**/
$html_decimalcodes = array("​","◀");
preg_match_all('/[\xE0-\xFF][\x80-\xFF]{2}|./', $str, $match); // target for BMP
$m = $match[0];
$slen = strlen($str); // length of source string
$tlen = strlen($tail); // length of tail string
$mlen = count($m); // length of matched characters
if ($slen <= $len)
{
/*echo $str;
echo '
';*/
$str = str_replace($html_decimalcodes,"", $str);
/*echo $str;
echo '
';*/
return $str;
}
if (!$checkmb && $mlen <= $len)
{
/*echo $str;
echo '
';*/
$str = str_replace($html_decimalcodes,"", $str);
/*echo $str;
echo '
';*/
return $str;
}
$ret = array();
$count = 0;
for($i=0; $i < $len; $i++) {
$count += ($checkmb && strlen($m[$i]) > 1)?2:1;
if($count + $tlen > $len) break;
$ret[] = $m[$i];
}
$text = html_entity_decode(join('', $ret).$tail);
/*echo $text;
echo '
';*/
$text = str_replace($html_decimalcodes,"", $text);
/*echo $text;
echo '
';*/
return $text;
}
XML to Array
function XMLtoArrayFormat($XML)
{
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $XML, $vals);
xml_parser_free($xml_parser);
// wyznaczamy tablice z powtarzajacymi sie tagami na tym samym poziomie
$_tmp='';
foreach ($vals as $xml_elem) {
$x_tag=$xml_elem['tag'];
$x_level=$xml_elem['level'];
$x_type=$xml_elem['type'];
if ($x_level!=1 && $x_type == 'close') {
if (isset($multi_key[$x_tag][$x_level]))
$multi_key[$x_tag][$x_level]=1;
else
$multi_key[$x_tag][$x_level]=0;
}
if ($x_level!=1 && $x_type == 'complete') {
if ($_tmp==$x_tag)
$multi_key[$x_tag][$x_level]=1;
$_tmp=$x_tag;
}
}
// jedziemy po tablicy
foreach ($vals as $xml_elem) {
$x_tag=$xml_elem['tag'];
$x_level=$xml_elem['level'];
$x_type=$xml_elem['type'];
if ($x_type == 'open')
$level[$x_level] = $x_tag;
$start_level = 1;
$php_stmt = '$xml_array';
if ($x_type=='close' && $x_level!=1)
$multi_key[$x_tag][$x_level]++;
while ($start_level < $x_level) {
$php_stmt .= '[$level['.$start_level.']]';
if (isset($multi_key[$level[$start_level]][$start_level]) && $multi_key[$level[$start_level]][$start_level])
$php_stmt .= '['.($multi_key[$level[$start_level]][$start_level]-1).']';
$start_level++;
}
$add='';
if (isset($multi_key[$x_tag][$x_level]) && $multi_key[$x_tag][$x_level] && ($x_type=='open' || $x_type=='complete')) {
if (!isset($multi_key2[$x_tag][$x_level]))
$multi_key2[$x_tag][$x_level]=0;
else
$multi_key2[$x_tag][$x_level]++;
$add='['.$multi_key2[$x_tag][$x_level].']';
}
if (isset($xml_elem['value']) && trim($xml_elem['value'])!='' && !array_key_exists('attributes', $xml_elem)) {
if ($x_type == 'open')
$php_stmt_main=$php_stmt.'[$x_type]'.$add.'[\'content\'] = $xml_elem[\'value\'];';
else
$php_stmt_main=$php_stmt.'[$x_tag]'.$add.' = $xml_elem[\'value\'];';
eval($php_stmt_main);
}
if (array_key_exists('attributes', $xml_elem)) {
if (isset($xml_elem['value'])) {
$php_stmt_main=$php_stmt.'[$x_tag]'.$add.'[\'content\'] = $xml_elem[\'value\'];';
eval($php_stmt_main);
}
foreach ($xml_elem['attributes'] as $key=>$value) {
$php_stmt_att=$php_stmt.'[$x_tag]'.$add.'[$key] = $value;';
eval($php_stmt_att);
}
}
}
return $xml_array;
}
{
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $XML, $vals);
xml_parser_free($xml_parser);
// wyznaczamy tablice z powtarzajacymi sie tagami na tym samym poziomie
$_tmp='';
foreach ($vals as $xml_elem) {
$x_tag=$xml_elem['tag'];
$x_level=$xml_elem['level'];
$x_type=$xml_elem['type'];
if ($x_level!=1 && $x_type == 'close') {
if (isset($multi_key[$x_tag][$x_level]))
$multi_key[$x_tag][$x_level]=1;
else
$multi_key[$x_tag][$x_level]=0;
}
if ($x_level!=1 && $x_type == 'complete') {
if ($_tmp==$x_tag)
$multi_key[$x_tag][$x_level]=1;
$_tmp=$x_tag;
}
}
// jedziemy po tablicy
foreach ($vals as $xml_elem) {
$x_tag=$xml_elem['tag'];
$x_level=$xml_elem['level'];
$x_type=$xml_elem['type'];
if ($x_type == 'open')
$level[$x_level] = $x_tag;
$start_level = 1;
$php_stmt = '$xml_array';
if ($x_type=='close' && $x_level!=1)
$multi_key[$x_tag][$x_level]++;
while ($start_level < $x_level) {
$php_stmt .= '[$level['.$start_level.']]';
if (isset($multi_key[$level[$start_level]][$start_level]) && $multi_key[$level[$start_level]][$start_level])
$php_stmt .= '['.($multi_key[$level[$start_level]][$start_level]-1).']';
$start_level++;
}
$add='';
if (isset($multi_key[$x_tag][$x_level]) && $multi_key[$x_tag][$x_level] && ($x_type=='open' || $x_type=='complete')) {
if (!isset($multi_key2[$x_tag][$x_level]))
$multi_key2[$x_tag][$x_level]=0;
else
$multi_key2[$x_tag][$x_level]++;
$add='['.$multi_key2[$x_tag][$x_level].']';
}
if (isset($xml_elem['value']) && trim($xml_elem['value'])!='' && !array_key_exists('attributes', $xml_elem)) {
if ($x_type == 'open')
$php_stmt_main=$php_stmt.'[$x_type]'.$add.'[\'content\'] = $xml_elem[\'value\'];';
else
$php_stmt_main=$php_stmt.'[$x_tag]'.$add.' = $xml_elem[\'value\'];';
eval($php_stmt_main);
}
if (array_key_exists('attributes', $xml_elem)) {
if (isset($xml_elem['value'])) {
$php_stmt_main=$php_stmt.'[$x_tag]'.$add.'[\'content\'] = $xml_elem[\'value\'];';
eval($php_stmt_main);
}
foreach ($xml_elem['attributes'] as $key=>$value) {
$php_stmt_att=$php_stmt.'[$x_tag]'.$add.'[$key] = $value;';
eval($php_stmt_att);
}
}
}
return $xml_array;
}
Saturday, September 3, 2011
Google Translation Gadget
<div id="google_translate_element" style="display:none"></div>
<div id="translate_link" style="margin-bottom:14px">
<a href="#" class="topnav"
onclick="document.getElementById('google_translate_element').style.display='inline';document.getElementById('translate_link').style.display='none';return false;">
TRANSLATE
</a>
</div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
autoDisplay: false,
gaTrack: true,
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
}
</script><script src="//transl>ate.google.com/translate_a/element.js?cb=googleTranslateElementInit" type="text/javascript"></script>
<div id="translate_link" style="margin-bottom:14px">
<a href="#" class="topnav"
onclick="document.getElementById('google_translate_element').style.display='inline';document.getElementById('translate_link').style.display='none';return false;">
TRANSLATE
</a>
</div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
autoDisplay: false,
gaTrack: true,
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
}
</script><script src="//transl>ate.google.com/translate_a/element.js?cb=googleTranslateElementInit" type="text/javascript"></script>
Captcha Reload
<img id="captcha" src="/securimage_show.php?0.13967828042965524" alt="CAPTCHA Image"><a href="#" style="background: none repeat scroll 0% 0% rgb(236, 236, 236);"
onclick="document.getElementById('captcha').src = '/securimage_show.php?' + Math.random(); return false">Reload Image</a>
Wednesday, August 31, 2011
Single Query Dynamic Multi-level Menu
Since writing Dynamic Multi-level CSS Menu with PHP and MySQL. SEO Ready I have learned quite a lot and in doing so found a much more efficient way of building this menu. This method varies in that it only makes one query to the menu table and compiles the results into a multidimensional array. The basic recurring function was just about the same, just taking into account the changes in data structure. Lets start with the query and array.
01 | // Select all entries from the menu table |
02 | $result=mysql_query("SELECT id, label, link, parent FROM menu ORDER BY parent, sort, label"); |
03 | // Create a multidimensional array to conatin a list of items and parents |
04 | $menu = array( |
05 | 'items' => array(), |
06 | 'parents' => array() |
07 | ); |
08 | // Builds the array lists with data from the menu table |
09 | while ($items = mysql_fetch_assoc($result)) |
10 | { |
11 | // Creates entry into items array with current menu item id ie. $menu['items'][1] |
12 | $menu['items'][$items['id']] = $items; |
13 | // Creates entry into parents array. Parents array contains a list of all items with children |
14 | $menu['parents'][$items['parent']][] = $items['id']; |
15 | } |
The $menu contains 2 other arrays, items holds every result from the menu table query, the parents array holds a list of all item ids that have children. Next we use a while statement to run through the sql results and assign items to the arrays. If the items parent id already exists in the parents array it will be overwritten so there will only be 1 of each parent id listed.
01 | // Menu builder function, parentId 0 is the root |
02 | function buildMenu($parent, $menu) |
03 | { |
04 | $html = ""; |
05 | if (isset($menu['parents'][$parent])) |
06 | { |
07 | $html .= " |
08 | \n"; |
09 | foreach ($menu['parents'][$parent] as $itemId) |
10 | { |
11 | if(!isset($menu['parents'][$itemId])) |
12 | { |
13 | $html .= "\n .$menu['items'][$itemId]['link']."'>".$menu['items'][$itemId]['label']."\n \n"; |
14 | } |
15 | if(isset($menu['parents'][$itemId])) |
16 | { |
17 | $html .= " |
19 | $html .= buildMenu($itemId, $menu); |
20 | $html .= " \n"; |
21 | } |
22 | } |
23 | $html .= " \n"; |
24 | } |
25 | return $html; |
26 | } |
27 | echo buildMenu(0, $menu); |
This version signifigantly reduces the strain on your server if you have hundreds or thousands of pages and still allows you to keep a completely dynamic menu.
Subscribe to:
Posts (Atom)