mis requête à l'intérieur d'une fonction en PHP

  • northstjarna
  • Beginner
  • Beginner
  • No Avatar
  • Inscription: Nov 14, 2006
  • Messages: 58
  • Loc: Chertsey, UK
  • Status: Offline

Message Avril 26th, 2010, 3:46 pm

Salut à essayer de mettre une requête dans une fonction ne sais pas son possible de le faire en PHP. Peut-on faire dans ColdFusion.
Fondamentalement, je veux appeler une requête récursive qui est sélectionnable via une pièce d'identité.

Code: [ Select ]
function getmenu($menu_id){
    /* get the top most level menu */
    mysql_select_db($database_eggbox, $eggbox);
    $query_top_menu = "select * from menu where menu_parent_menu_id = $menu_id";
    $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
    $row_top_menu = mysql_fetch_assoc($top_menu);
    $totalRows_top_menu = mysql_num_rows($top_menu);

    /* loop and echo */

}

getmenu(0);
  1. function getmenu($menu_id){
  2.     /* get the top most level menu */
  3.     mysql_select_db($database_eggbox, $eggbox);
  4.     $query_top_menu = "select * from menu where menu_parent_menu_id = $menu_id";
  5.     $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
  6.     $row_top_menu = mysql_fetch_assoc($top_menu);
  7.     $totalRows_top_menu = mysql_num_rows($top_menu);
  8.     /* loop and echo */
  9. }
  10. getmenu(0);


Sa me disant que je ne peux pas faire cela dans une fonction.

Avertissement: mysql_select_db (): argument fourni n'est pas une ressource valide MySQL-Link Library....

Comment pourrais-je y parvenir? Peut-être dans une classe?

Toute aide Merci

Andi
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Avril 26th, 2010, 3:46 pm

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Inscription: Fév 10, 2004
  • Messages: 13455
  • Loc: Florida
  • Status: Offline

Message Avril 26th, 2010, 3:52 pm

Vous devez utiliser le "global" mot-clé pour rendre le database_eggbox $ et d'autres variables pertinentes visible à l'intérieur de la fonction.

PHP Code: [ Select ]
function getmenu($menu_id)
{
  global $database_eggbox, $eggbox;
  // ...
}
  1. function getmenu($menu_id)
  2. {
  3.   global $database_eggbox, $eggbox;
  4.   // ...
  5. }


Ou bien, passez les variables pertinentes comme arguments dans la fonction.

PHP Code: [ Select ]
function getmenu($menu_id, $database_eggbox, $eggbox){}
  • northstjarna
  • Beginner
  • Beginner
  • No Avatar
  • Inscription: Nov 14, 2006
  • Messages: 58
  • Loc: Chertsey, UK
  • Status: Offline

Message Avril 26th, 2010, 11:41 pm

Bien sûr, maintenant.... Got it travail...

Code: [ Select ]
    mysql_select_db($database_eggbox, $eggbox);
        
        
    

    
    function getmenu($menu_id){
        
        
        /* get the top most level menu */
        global $database_eggbox, $eggbox;
        $query_top_menu = "select * from menu where menu_parent_menu_id = $menu_id";
        $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
        $row_top_menu = mysql_fetch_assoc($top_menu);
        $totalRows_top_menu = mysql_num_rows($top_menu);
        
        
        
        do {
          echo $row_top_menu['menu_text'];
        } while ($row_top_menu = mysql_fetch_assoc($top_menu));

    }
  1.     mysql_select_db($database_eggbox, $eggbox);
  2.         
  3.         
  4.     
  5.     
  6.     function getmenu($menu_id){
  7.         
  8.         
  9.         /* get the top most level menu */
  10.         global $database_eggbox, $eggbox;
  11.         $query_top_menu = "select * from menu where menu_parent_menu_id = $menu_id";
  12.         $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
  13.         $row_top_menu = mysql_fetch_assoc($top_menu);
  14.         $totalRows_top_menu = mysql_num_rows($top_menu);
  15.         
  16.         
  17.         
  18.         do {
  19.           echo $row_top_menu['menu_text'];
  20.         } while ($row_top_menu = mysql_fetch_assoc($top_menu));
  21.     }


Juste besoin d'un peu plus de code pour faire fonctionner de manière récursive maintenant; o)

Merci pour votre aide
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Inscription: Fév 10, 2004
  • Messages: 13455
  • Loc: Florida
  • Status: Offline

Message Avril 27th, 2010, 8:47 am

Maintenant que la question est résolue, je devrais probablement mentionner que l'aide d'une requête récursive est généralement pas une bonne chose à faire.

Il semble que vous êtes la construction d'une hiérarchie, ce qui peut être fait avec une requête et deux boucles, si vous utilisez un item_id pour vos clés du tableau et des références à son tour un tableau à une dimension dans un tableau virtuel multi-dimensionnelle.

Ceci est pris d'un autre site si sa ne va pas correspondre avec votre code, mais j'espère que le concept est facile à voir. :)

PHP Code: [ Select ]
$category_lineage = array();
 
$result = $db->query('SELECT category_id, parent_id, label FROM ' . CATEGORIES_TABLE, MYSQLI_USE_RESULT);
while($row = $result->fetch_object())
{
   $row->sub_categories = array();
   $category_lineage[$row->category_id] = $row;
}
$result->close();
 
foreach($category_lineage as $key => $val)
{
   if($val->parent_id)
   {
      $category_lineage[$val->parent_id]->sub_categories[$key] =& $category_lineage[$key];
   }
}
  1. $category_lineage = array();
  2.  
  3. $result = $db->query('SELECT category_id, parent_id, label FROM ' . CATEGORIES_TABLE, MYSQLI_USE_RESULT);
  4. while($row = $result->fetch_object())
  5. {
  6.    $row->sub_categories = array();
  7.    $category_lineage[$row->category_id] = $row;
  8. }
  9. $result->close();
  10.  
  11. foreach($category_lineage as $key => $val)
  12. {
  13.    if($val->parent_id)
  14.    {
  15.       $category_lineage[$val->parent_id]->sub_categories[$key] =& $category_lineage[$key];
  16.    }
  17. }
Strong with this one, the sudo is.
  • northstjarna
  • Beginner
  • Beginner
  • No Avatar
  • Inscription: Nov 14, 2006
  • Messages: 58
  • Loc: Chertsey, UK
  • Status: Offline

Message Avril 27th, 2010, 10:35 am

Salut là quand je voulais dire récursif que je voulais dire comme ceci.... ; O)

de haut niveau
niveau sous-
sous sous niveau
niveau sous-
de haut niveau

Cela fonctionne même si je ne sais pas si c'est le moyen le plus efficace de le faire.


Code: [ Select ]

function getmenu($menu_level){
        
        /* get the top most level menu */
        global $database_eggbox, $eggbox;
        $query_top_menu = "select * from menu where menu_parent_menu_id = 0 order by menu_display_order";
        $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
        $row_top_menu = mysql_fetch_assoc($top_menu);
        $totalRows_top_menu = mysql_num_rows($top_menu);
    
        if ($menu_level <> 0) {
                            
            echo "<ul>";
                             
            do {
             
              echo "<li><a href='index.php?' title='opens in same window' target='_self' >" . $row_top_menu['menu_text'] . "</a>";
                $menuid = $row_top_menu['menu_id'];
                $query_has_children = "select * from menu where menu_parent_menu_id = $menuid order by menu_display_order";
                $has_children = mysql_query($query_has_children, $eggbox) or die(mysql_error());
                $row_has_children = mysql_fetch_assoc($has_children);
                $totalRows_has_children = mysql_num_rows($has_children);
                if($totalRows_has_children > 0){
                    
                    getchildren($menuid,0);     
             
                  } else {
                    echo "</li>";
                }
            } while ($row_top_menu = mysql_fetch_assoc($top_menu));
                
                
            echo "</ul>";
        
        } elseif ($menu_level == 0) {
                        
            echo "<ul>";
                             
            do {
             
              echo "<li><a href='index.php?' title='opens in same window' target='_self' >" . $row_top_menu['menu_text'] . "</a></li>";
            
            } while ($row_top_menu = mysql_fetch_assoc($top_menu));
            
            echo "</ul>";
        }

    } // End Function


    function getchildren ($menuid,$count) {
                    
        /* get the next level menu */
        global $database_eggbox, $eggbox;
        $query_child_menu = "select * from menu where menu_parent_menu_id = $menuid order by menu_display_order";
        $child_menu = mysql_query($query_child_menu, $eggbox) or die(mysql_error());
        $row_child_menu = mysql_fetch_assoc($child_menu);
        $totalRows_child_menu = mysql_num_rows($child_menu);      
                        
        
        do {
        
            if($count == 0) {
                echo "<ul>";
            }
        
            echo "<li><a href='index.php?' title='opens in same window' target='_self' >" . $row_child_menu['menu_text'] . "</a>";
            $menuidd = $row_child_menu['menu_id'];
            $query_has_childrens = "select * from menu where menu_parent_menu_id = $menuidd order by menu_display_order";
            $has_childrens = mysql_query($query_has_childrens, $eggbox) or die(mysql_error());
            $row_has_childrens = mysql_fetch_assoc($has_childrens);
            $totalRows_has_childrens = mysql_num_rows($has_childrens);
                
            if($totalRows_has_childrens > 0){
                    
                    getchildren($menuidd,0);
                
            } else {
                "</li>";
            }            
    
            if($count+1 == $totalRows_child_menu) {
                echo "</ul>";
            }
        
            $count += 1;        
        } while ($row_child_menu = mysql_fetch_assoc($child_menu));        
                        
    } // end function
  1. function getmenu($menu_level){
  2.         
  3.         /* get the top most level menu */
  4.         global $database_eggbox, $eggbox;
  5.         $query_top_menu = "select * from menu where menu_parent_menu_id = 0 order by menu_display_order";
  6.         $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
  7.         $row_top_menu = mysql_fetch_assoc($top_menu);
  8.         $totalRows_top_menu = mysql_num_rows($top_menu);
  9.     
  10.         if ($menu_level <> 0) {
  11.                             
  12.             echo "<ul>";
  13.                              
  14.             do {
  15.              
  16.               echo "<li><a href='index.php?' title='opens in same window' target='_self' >" . $row_top_menu['menu_text'] . "</a>";
  17.                 $menuid = $row_top_menu['menu_id'];
  18.                 $query_has_children = "select * from menu where menu_parent_menu_id = $menuid order by menu_display_order";
  19.                 $has_children = mysql_query($query_has_children, $eggbox) or die(mysql_error());
  20.                 $row_has_children = mysql_fetch_assoc($has_children);
  21.                 $totalRows_has_children = mysql_num_rows($has_children);
  22.                 if($totalRows_has_children > 0){
  23.                     
  24.                     getchildren($menuid,0);     
  25.              
  26.                   } else {
  27.                     echo "</li>";
  28.                 }
  29.             } while ($row_top_menu = mysql_fetch_assoc($top_menu));
  30.                 
  31.                 
  32.             echo "</ul>";
  33.         
  34.         } elseif ($menu_level == 0) {
  35.                         
  36.             echo "<ul>";
  37.                              
  38.             do {
  39.              
  40.               echo "<li><a href='index.php?' title='opens in same window' target='_self' >" . $row_top_menu['menu_text'] . "</a></li>";
  41.             
  42.             } while ($row_top_menu = mysql_fetch_assoc($top_menu));
  43.             
  44.             echo "</ul>";
  45.         }
  46.     } // End Function
  47.     function getchildren ($menuid,$count) {
  48.                     
  49.         /* get the next level menu */
  50.         global $database_eggbox, $eggbox;
  51.         $query_child_menu = "select * from menu where menu_parent_menu_id = $menuid order by menu_display_order";
  52.         $child_menu = mysql_query($query_child_menu, $eggbox) or die(mysql_error());
  53.         $row_child_menu = mysql_fetch_assoc($child_menu);
  54.         $totalRows_child_menu = mysql_num_rows($child_menu);      
  55.                         
  56.         
  57.         do {
  58.         
  59.             if($count == 0) {
  60.                 echo "<ul>";
  61.             }
  62.         
  63.             echo "<li><a href='index.php?' title='opens in same window' target='_self' >" . $row_child_menu['menu_text'] . "</a>";
  64.             $menuidd = $row_child_menu['menu_id'];
  65.             $query_has_childrens = "select * from menu where menu_parent_menu_id = $menuidd order by menu_display_order";
  66.             $has_childrens = mysql_query($query_has_childrens, $eggbox) or die(mysql_error());
  67.             $row_has_childrens = mysql_fetch_assoc($has_childrens);
  68.             $totalRows_has_childrens = mysql_num_rows($has_childrens);
  69.                 
  70.             if($totalRows_has_childrens > 0){
  71.                     
  72.                     getchildren($menuidd,0);
  73.                 
  74.             } else {
  75.                 "</li>";
  76.             }            
  77.     
  78.             if($count+1 == $totalRows_child_menu) {
  79.                 echo "</ul>";
  80.             }
  81.         
  82.             $count += 1;        
  83.         } while ($row_child_menu = mysql_fetch_assoc($child_menu));        
  84.                         
  85.     } // end function


Merci de votre compréhension si...
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Inscription: Fév 10, 2004
  • Messages: 13455
  • Loc: Florida
  • Status: Offline

Message Avril 27th, 2010, 11:38 am

Ouais, je vois ce que vous faites. Vous semblez être sur une sorte de délai mais, ce qui signifie que vous n'avez pas le temps de retravailler rien, alors je ne vais pas perdre une ou l'autre de notre temps à parler dans une oreille et sort par l'autre. :)
Strong with this one, the sudo is.
  • northstjarna
  • Beginner
  • Beginner
  • No Avatar
  • Inscription: Nov 14, 2006
  • Messages: 58
  • Loc: Chertsey, UK
  • Status: Offline

Message Avril 28th, 2010, 12:43 pm

Non pas sur un délai juste essayer de faire les choses à travailler bien...
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Inscription: Fév 10, 2004
  • Messages: 13455
  • Loc: Florida
  • Status: Offline

Message Avril 28th, 2010, 2:29 pm

Pourquoi êtes-vous brosser ce que j'ai à dire hors?

Quote:
Merci de votre compréhension si...


Quels sont les points de suspension pour remplacer?

Quote:
Merci de votre compréhension si, [crétin]

Quote:
Merci de votre compréhension bien, [mais je ne comprends pas quelque chose]

Quote:
Merci de votre compréhension si, [permet de voir combien de temps je peux vous troll]


Quelles sont vos intentions!
Strong with this one, the sudo is.
  • northstjarna
  • Beginner
  • Beginner
  • No Avatar
  • Inscription: Nov 14, 2006
  • Messages: 58
  • Loc: Chertsey, UK
  • Status: Offline

Message Avril 29th, 2010, 1:34 am

Salut à tous,

Im un développeur coldsufion si mes compétences PHP sont devenus un peu ropey Im peur...
Ma première question était de savoir comment mettre une requête dans une fonction. Vous avez bien voulu me montrait comment faire alors Merci.

Quote:
Pourquoi êtes-vous brosser ce que j'ai à dire hors?

Désolé Im pas le brossage de ce que vous dites. J'étais mearly vous remercier. Je vois ce que vous faisiez ce qui est utile que je peut essayer ..

Quote:
Quels sont les points de suspension pour remplacer?

Ill après l'ensemble du code plus tard si vous pouvez le voir. Ne pas l'avoir avec moi en ce moment, et Im travaille toujours...J'ai maintenant de faire le menu rétractable et extensible qui est la prochaine chose délicate.

Je suis le crétin oui...: O)
  • northstjarna
  • Beginner
  • Beginner
  • No Avatar
  • Inscription: Nov 14, 2006
  • Messages: 58
  • Loc: Chertsey, UK
  • Status: Offline

Message Mai 1st, 2010, 2:24 am

Ok Baby Cakes je vous ai promis le code, mais le haut débit a diminué. Mais voici tout ce que finalement...Tout système récursif menu pliant. Si vous pensez que je peux l'améliorer alors s'il vous plaît faites le moi savoir que je pense toujours qu'il ya une meilleure façon de le faire. Mes compétences en PHP sont encore assez ropey que je viens d'un milieu FC...mais ho hum c'est ici...

Code: [ Select ]
mysql_select_db($database_eggbox, $eggbox);

/* get the home page at start*/
$query_default_url = "select * from menu where menu_text = 'Home' order by menu_display_order";
$default_url = mysql_query($query_default_url, $eggbox) or die(mysql_error());
$row_default_url = mysql_fetch_assoc($default_url);
$totalRows_default_url = mysql_num_rows($default_url);

if (isset($_GET['menu_id'])) {
    $urlmenu_id = $_GET['menu_id'];
} else {
    $urlmenu_id = $row_default_url['menu_id'];
}



///////////////////////////////////////////////////////////////
/////////////////////* functions */////////////////////////////
///////////////////////////////////////////////////////////////

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 switch ($theType) {
  case "text":
   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
   break;  
  case "long":
  case "int":
   $theValue = ($theValue != "") ? intval($theValue) : "NULL";
   break;
  case "double":
   $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
   break;
  case "date":
   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
   break;
  case "defined":
   $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
   break;
 }
 return $theValue;
}
}

/* get breadcrumb function */
function getbreadcrumb($arraycount,$parentmenuid){
    
    /* get the current level menu */
    global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;
    $query_last_breadcrumb = "select * from menu where menu_id = $parentmenuid order by menu_display_order";
    $last_breadcrumb = mysql_query($query_last_breadcrumb, $eggbox) or die(mysql_error());
    $row_last_breadcrumb = mysql_fetch_assoc($last_breadcrumb);
    $totalRows_last_breadcrumb = mysql_num_rows($last_breadcrumb);
    
    $array_menu[$arraycount][0] = $row_last_breadcrumb['menu_id'];
    $array_menu[$arraycount][1] = $row_last_breadcrumb['page_id'];
    $array_menu[$arraycount][2] = $row_last_breadcrumb['menu_text'];
    $array_menu[$arraycount][3] = $row_last_breadcrumb['menu_parent_menu_id'];
    
    if($array_menu[$arraycount][0] != "") {
        getbreadcrumb($arraycount+1,$array_menu[$arraycount][3]);
    }
    
    if($arraycount == count){
        echo $array_menu[$arraycount][2];
    } else {
        $menuid = $array_menu[$arraycount][0];
        echo "<li><a href='index.php?menu_id=$menuid' title='opens in same window' target='_self' >" . $array_menu[$arraycount][2] . "</a> : </li>";
    }
    mysql_free_result($last_breadcrumb);
} // end function


/* get menu functions */
function getmenu($menu_level,$menuid){
        
    /* get the top most level menu */
    global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;
    $query_top_menu = "select * from menu where menu_parent_menu_id = $menuid and menu_display = 1 order by menu_display_order";
    $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
    $row_top_menu = mysql_fetch_assoc($top_menu);
    $totalRows_top_menu = mysql_num_rows($top_menu);
    
    
    if ($menu_level == 0) { // Top menu for nav bar only
                    
        echo "<ul>";
                         
        do {
              $menuid = $row_top_menu['menu_id'];
            if($urlmenu_id == $menuid) {
                $selectedclass = "class='selected'";
            } else {
                $selectedclass = "";
            }
            
              if($row_top_menu['menu_alt_location'] != "") {
                // Alternative location like google
                  if(substr($row_top_menu['menu_alt_location'],0,4) == "http") { $menuurl = $row_top_menu['menu_alt_location']; } else { $menuurl = "http://" . $row_top_menu['menu_alt_location'];}
                  $title = "opens in new window";
                $target = "_blank";                
              } else {
                  // site menu
                $menuurl = "index.php?menu_id=$menuid";
                  $title = "opens in same window";
                $target = "_self";
            } // End if
            
            echo "<li><a href='$menuurl' title='$target' target='$target' $selectedclass >" . $row_top_menu['menu_text'] . "</a></li>";
            
        } while ($row_top_menu = mysql_fetch_assoc($top_menu));
        
        echo "</ul>";
    
    
    } elseif ($menu_level == 1) {
            
            if($totalRows_top_menu > 0) { // full side menu and you don't want a top menu
                    
                echo "<ul>";
                $count = 0;    
                
                do {
                  $menuid = $row_top_menu['menu_id'];
                  if($urlmenu_id == $menuid) {
                        $selectedclass = "class='selected'";
                    } else {
                        $selectedclass = "";
                    }
                 
                  if($row_top_menu['menu_alt_location'] != "") {
                        // Alternative location like google
                        if(substr($row_top_menu['menu_alt_location'],0,4) == "http") { $menuurl = $row_top_menu['menu_alt_location']; } else { $menuurl = "http://" . $row_top_menu['menu_alt_location'];}
                        $title = "opens in new window";
                        $target = "_blank";                
                    } else {
                        // Site menu
                        $menuurl = "index.php?menu_id=$menuid";
                        $title = "opens in same window";
                        $target = "_self";
                    } // End if
                 
                  echo "<li><a href='$menuurl' title='$title' target='$target' >" . $row_top_menu['menu_text'] . "</a>";
                    
                    $query_has_children = "select * from menu where menu_parent_menu_id = $menuid and menu_display = 1 order by menu_display_order";
                    $has_children = mysql_query($query_has_children, $eggbox) or die(mysql_error());
                    $row_has_children = mysql_fetch_assoc($has_children);
                    $totalRows_has_children = mysql_num_rows($has_children);
                    
                    if($totalRows_has_children > 0 && $array_menu[sizeof($array_menu)-2][0] == $menuid){
                        getchildren($menuid,0,3);
                        echo "</li>";      
                    } else {
                        echo "</li>";
                    }
                    
                    $count += 1;        
                } while ($row_top_menu = mysql_fetch_assoc($top_menu));
                
                echo "</ul>";
                
                
            } // End if
    
            mysql_free_result($has_children);
    } elseif ($menu_level == 2) { // Second level menu based on top level menu
        
        if($totalRows_top_menu > 0) {
                    
                $count = 0;    
                
                do {
                      $menuid = $row_top_menu['menu_id'];
                      $query_has_children = "select * from menu where menu_parent_menu_id = $menuid and menu_display = 1 order by menu_display_order";
                    $has_children = mysql_query($query_has_children, $eggbox) or die(mysql_error());
                    $row_has_children = mysql_fetch_assoc($has_children);
                    $totalRows_has_children = mysql_num_rows($has_children);
                    
                    if($totalRows_has_children > 0 && $array_menu[sizeof($array_menu)-2][0] == $menuid){
                        getchildren($menuid,0,3);
                        
                    }
                    
                        
                    $count += 1;        
                } while ($row_top_menu = mysql_fetch_assoc($top_menu));
                        
        } // End if
        mysql_free_result($has_children);
    } // End if function for menu levels        
    
    mysql_free_result($top_menu);
} // End Function


function getchildren ($menuid,$count,$count_level) {
                
    /* get the next level menu */
    global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;
    $query_child_menu = "select * from menu where menu_parent_menu_id = $menuid and menu_display = 1 order by menu_display_order";
    $child_menu = mysql_query($query_child_menu, $eggbox) or die(mysql_error());
    $row_child_menu = mysql_fetch_assoc($child_menu);
    $totalRows_child_menu = mysql_num_rows($child_menu);      
        
    
    do {
        
        if($count == 0) {
            echo "<ul>";
        }
        
        $menuidd = $row_child_menu['menu_id'];
        if($urlmenu_id == $menuidd) {
            $selectedclass = "class='selected'";
        } else {
            $selectedclass = "";
        }
        
        if($row_child_menu['menu_alt_location'] != "") {
            // Alternative location like google
            if(substr($row_child_menu['menu_alt_location'],0,4) == "http") { $menuurl = $row_child_menu['menu_alt_location']; } else { $menuurl = "http://" . $row_child_menu['menu_alt_location'];}
            $title = "opens in new window";
            $target = "_blank";                
        } else {
            // site menu
            $menuurl = "index.php?menu_id=$menuidd";
            $title = "opens in same window";
            $target = "_self";
        } // End if
        
        echo "<li><a href='$menuurl' title='$title' target='$target' $selectedclass >" . $row_child_menu['menu_text'] . "</a>";
        
        $query_has_childrens = "select * from menu where menu_parent_menu_id = $menuidd and menu_display = 1 order by menu_display_order";
        $has_childrens = mysql_query($query_has_childrens, $eggbox) or die(mysql_error());
        $row_has_childrens = mysql_fetch_assoc($has_childrens);
        $totalRows_has_childrens = mysql_num_rows($has_childrens);
            
        if($totalRows_has_childrens > 0 && $array_menu[sizeof($array_menu)-$count_level][0] == $menuidd){
                
                getchildren($menuidd,0,$count_level+1);
                echo "</li>";
        } else {
                echo "</li>";
        }
                
        if($count+1 == $totalRows_child_menu) {
            echo "</ul>";
        }
    
        $count += 1;
                
    } while ($row_child_menu = mysql_fetch_assoc($child_menu));
    mysql_free_result($has_childrens);
    mysql_free_result($child_menu);
} // end function


/* get content */
$query_page_info = "select menu_id, pages.* from pages inner join menu on pages.page_id = menu.page_id where menu.menu_id = $urlmenu_id";
$page_info = mysql_query($query_page_info, $eggbox) or die(mysql_error());
$row_page_info = mysql_fetch_assoc($page_info);
$totalRows_page_info = mysql_num_rows($page_info);

function getcontent($content){
    global $row_page_info;
    $content = $row_page_info[$content];
    return $content;
} // End function

function getcolumns() {
    global $database_eggbox, $eggbox, $row_page_info, $urlmenu_id;
        
    $query_top_top_menu = "select * from menu where menu_parent_menu_id = $urlmenu_id and menu_display = 1 order by menu_display_order";
    $top_top_menu = mysql_query($query_top_top_menu, $eggbox) or die(mysql_error());
    $row_top_top_menu = mysql_fetch_assoc($top_top_menu);
    $totalRows_top_top_menu = mysql_num_rows($top_top_menu);
    
    if($row_page_info['page_lhs_content'] == "" && $row_page_info['page_rhs_content'] == "" && $totalRows_top_top_menu == 0) {
        $collhsrhs = "-noLHSRHS";
    } elseif($row_page_info['page_rhs_content'] == "" ) {
        $collhsrhs = "-noRHS";
    } elseif ($row_page_info['page_lhs_content'] == "" || $row_top_top_menu == 0) {
        $collhsrhs = "-noLHS";
    } else {
        $collhsrhs = "";
    }
    
    return $collhsrhs;
}




mysql_free_result($page_info);
  1. mysql_select_db($database_eggbox, $eggbox);
  2. /* get the home page at start*/
  3. $query_default_url = "select * from menu where menu_text = 'Home' order by menu_display_order";
  4. $default_url = mysql_query($query_default_url, $eggbox) or die(mysql_error());
  5. $row_default_url = mysql_fetch_assoc($default_url);
  6. $totalRows_default_url = mysql_num_rows($default_url);
  7. if (isset($_GET['menu_id'])) {
  8.     $urlmenu_id = $_GET['menu_id'];
  9. } else {
  10.     $urlmenu_id = $row_default_url['menu_id'];
  11. }
  12. ///////////////////////////////////////////////////////////////
  13. /////////////////////* functions */////////////////////////////
  14. ///////////////////////////////////////////////////////////////
  15. if (!function_exists("GetSQLValueString")) {
  16. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  17. {
  18.  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  19.  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  20.  switch ($theType) {
  21.   case "text":
  22.    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23.    break;  
  24.   case "long":
  25.   case "int":
  26.    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  27.    break;
  28.   case "double":
  29.    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  30.    break;
  31.   case "date":
  32.    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  33.    break;
  34.   case "defined":
  35.    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  36.    break;
  37.  }
  38.  return $theValue;
  39. }
  40. }
  41. /* get breadcrumb function */
  42. function getbreadcrumb($arraycount,$parentmenuid){
  43.     
  44.     /* get the current level menu */
  45.     global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;
  46.     $query_last_breadcrumb = "select * from menu where menu_id = $parentmenuid order by menu_display_order";
  47.     $last_breadcrumb = mysql_query($query_last_breadcrumb, $eggbox) or die(mysql_error());
  48.     $row_last_breadcrumb = mysql_fetch_assoc($last_breadcrumb);
  49.     $totalRows_last_breadcrumb = mysql_num_rows($last_breadcrumb);
  50.     
  51.     $array_menu[$arraycount][0] = $row_last_breadcrumb['menu_id'];
  52.     $array_menu[$arraycount][1] = $row_last_breadcrumb['page_id'];
  53.     $array_menu[$arraycount][2] = $row_last_breadcrumb['menu_text'];
  54.     $array_menu[$arraycount][3] = $row_last_breadcrumb['menu_parent_menu_id'];
  55.     
  56.     if($array_menu[$arraycount][0] != "") {
  57.         getbreadcrumb($arraycount+1,$array_menu[$arraycount][3]);
  58.     }
  59.     
  60.     if($arraycount == count){
  61.         echo $array_menu[$arraycount][2];
  62.     } else {
  63.         $menuid = $array_menu[$arraycount][0];
  64.         echo "<li><a href='index.php?menu_id=$menuid' title='opens in same window' target='_self' >" . $array_menu[$arraycount][2] . "</a> : </li>";
  65.     }
  66.     mysql_free_result($last_breadcrumb);
  67. } // end function
  68. /* get menu functions */
  69. function getmenu($menu_level,$menuid){
  70.         
  71.     /* get the top most level menu */
  72.     global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;
  73.     $query_top_menu = "select * from menu where menu_parent_menu_id = $menuid and menu_display = 1 order by menu_display_order";
  74.     $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
  75.     $row_top_menu = mysql_fetch_assoc($top_menu);
  76.     $totalRows_top_menu = mysql_num_rows($top_menu);
  77.     
  78.     
  79.     if ($menu_level == 0) { // Top menu for nav bar only
  80.                     
  81.         echo "<ul>";
  82.                          
  83.         do {
  84.               $menuid = $row_top_menu['menu_id'];
  85.             if($urlmenu_id == $menuid) {
  86.                 $selectedclass = "class='selected'";
  87.             } else {
  88.                 $selectedclass = "";
  89.             }
  90.             
  91.               if($row_top_menu['menu_alt_location'] != "") {
  92.                 // Alternative location like google
  93.                   if(substr($row_top_menu['menu_alt_location'],0,4) == "http") { $menuurl = $row_top_menu['menu_alt_location']; } else { $menuurl = "http://" . $row_top_menu['menu_alt_location'];}
  94.                   $title = "opens in new window";
  95.                 $target = "_blank";                
  96.               } else {
  97.                   // site menu
  98.                 $menuurl = "index.php?menu_id=$menuid";
  99.                   $title = "opens in same window";
  100.                 $target = "_self";
  101.             } // End if
  102.             
  103.             echo "<li><a href='$menuurl' title='$target' target='$target' $selectedclass >" . $row_top_menu['menu_text'] . "</a></li>";
  104.             
  105.         } while ($row_top_menu = mysql_fetch_assoc($top_menu));
  106.         
  107.         echo "</ul>";
  108.     
  109.     
  110.     } elseif ($menu_level == 1) {
  111.             
  112.             if($totalRows_top_menu > 0) { // full side menu and you don't want a top menu
  113.                     
  114.                 echo "<ul>";
  115.                 $count = 0;    
  116.                 
  117.                 do {
  118.                   $menuid = $row_top_menu['menu_id'];
  119.                   if($urlmenu_id == $menuid) {
  120.                         $selectedclass = "class='selected'";
  121.                     } else {
  122.                         $selectedclass = "";
  123.                     }
  124.                  
  125.                   if($row_top_menu['menu_alt_location'] != "") {
  126.                         // Alternative location like google
  127.                         if(substr($row_top_menu['menu_alt_location'],0,4) == "http") { $menuurl = $row_top_menu['menu_alt_location']; } else { $menuurl = "http://" . $row_top_menu['menu_alt_location'];}
  128.                         $title = "opens in new window";
  129.                         $target = "_blank";                
  130.                     } else {
  131.                         // Site menu
  132.                         $menuurl = "index.php?menu_id=$menuid";
  133.                         $title = "opens in same window";
  134.                         $target = "_self";
  135.                     } // End if
  136.                  
  137.                   echo "<li><a href='$menuurl' title='$title' target='$target' >" . $row_top_menu['menu_text'] . "</a>";
  138.                     
  139.                     $query_has_children = "select * from menu where menu_parent_menu_id = $menuid and menu_display = 1 order by menu_display_order";
  140.                     $has_children = mysql_query($query_has_children, $eggbox) or die(mysql_error());
  141.                     $row_has_children = mysql_fetch_assoc($has_children);
  142.                     $totalRows_has_children = mysql_num_rows($has_children);
  143.                     
  144.                     if($totalRows_has_children > 0 && $array_menu[sizeof($array_menu)-2][0] == $menuid){
  145.                         getchildren($menuid,0,3);
  146.                         echo "</li>";      
  147.                     } else {
  148.                         echo "</li>";
  149.                     }
  150.                     
  151.                     $count += 1;        
  152.                 } while ($row_top_menu = mysql_fetch_assoc($top_menu));
  153.                 
  154.                 echo "</ul>";
  155.                 
  156.                 
  157.             } // End if
  158.     
  159.             mysql_free_result($has_children);
  160.     } elseif ($menu_level == 2) { // Second level menu based on top level menu
  161.         
  162.         if($totalRows_top_menu > 0) {
  163.                     
  164.                 $count = 0;    
  165.                 
  166.                 do {
  167.                       $menuid = $row_top_menu['menu_id'];
  168.                       $query_has_children = "select * from menu where menu_parent_menu_id = $menuid and menu_display = 1 order by menu_display_order";
  169.                     $has_children = mysql_query($query_has_children, $eggbox) or die(mysql_error());
  170.                     $row_has_children = mysql_fetch_assoc($has_children);
  171.                     $totalRows_has_children = mysql_num_rows($has_children);
  172.                     
  173.                     if($totalRows_has_children > 0 && $array_menu[sizeof($array_menu)-2][0] == $menuid){
  174.                         getchildren($menuid,0,3);
  175.                         
  176.                     }
  177.                     
  178.                         
  179.                     $count += 1;        
  180.                 } while ($row_top_menu = mysql_fetch_assoc($top_menu));
  181.                         
  182.         } // End if
  183.         mysql_free_result($has_children);
  184.     } // End if function for menu levels        
  185.     
  186.     mysql_free_result($top_menu);
  187. } // End Function
  188. function getchildren ($menuid,$count,$count_level) {
  189.                 
  190.     /* get the next level menu */
  191.     global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;
  192.     $query_child_menu = "select * from menu where menu_parent_menu_id = $menuid and menu_display = 1 order by menu_display_order";
  193.     $child_menu = mysql_query($query_child_menu, $eggbox) or die(mysql_error());
  194.     $row_child_menu = mysql_fetch_assoc($child_menu);
  195.     $totalRows_child_menu = mysql_num_rows($child_menu);      
  196.         
  197.     
  198.     do {
  199.         
  200.         if($count == 0) {
  201.             echo "<ul>";
  202.         }
  203.         
  204.         $menuidd = $row_child_menu['menu_id'];
  205.         if($urlmenu_id == $menuidd) {
  206.             $selectedclass = "class='selected'";
  207.         } else {
  208.             $selectedclass = "";
  209.         }
  210.         
  211.         if($row_child_menu['menu_alt_location'] != "") {
  212.             // Alternative location like google
  213.             if(substr($row_child_menu['menu_alt_location'],0,4) == "http") { $menuurl = $row_child_menu['menu_alt_location']; } else { $menuurl = "http://" . $row_child_menu['menu_alt_location'];}
  214.             $title = "opens in new window";
  215.             $target = "_blank";                
  216.         } else {
  217.             // site menu
  218.             $menuurl = "index.php?menu_id=$menuidd";
  219.             $title = "opens in same window";
  220.             $target = "_self";
  221.         } // End if
  222.         
  223.         echo "<li><a href='$menuurl' title='$title' target='$target' $selectedclass >" . $row_child_menu['menu_text'] . "</a>";
  224.         
  225.         $query_has_childrens = "select * from menu where menu_parent_menu_id = $menuidd and menu_display = 1 order by menu_display_order";
  226.         $has_childrens = mysql_query($query_has_childrens, $eggbox) or die(mysql_error());
  227.         $row_has_childrens = mysql_fetch_assoc($has_childrens);
  228.         $totalRows_has_childrens = mysql_num_rows($has_childrens);
  229.             
  230.         if($totalRows_has_childrens > 0 && $array_menu[sizeof($array_menu)-$count_level][0] == $menuidd){
  231.                 
  232.                 getchildren($menuidd,0,$count_level+1);
  233.                 echo "</li>";
  234.         } else {
  235.                 echo "</li>";
  236.         }
  237.                 
  238.         if($count+1 == $totalRows_child_menu) {
  239.             echo "</ul>";
  240.         }
  241.     
  242.         $count += 1;
  243.                 
  244.     } while ($row_child_menu = mysql_fetch_assoc($child_menu));
  245.     mysql_free_result($has_childrens);
  246.     mysql_free_result($child_menu);
  247. } // end function
  248. /* get content */
  249. $query_page_info = "select menu_id, pages.* from pages inner join menu on pages.page_id = menu.page_id where menu.menu_id = $urlmenu_id";
  250. $page_info = mysql_query($query_page_info, $eggbox) or die(mysql_error());
  251. $row_page_info = mysql_fetch_assoc($page_info);
  252. $totalRows_page_info = mysql_num_rows($page_info);
  253. function getcontent($content){
  254.     global $row_page_info;
  255.     $content = $row_page_info[$content];
  256.     return $content;
  257. } // End function
  258. function getcolumns() {
  259.     global $database_eggbox, $eggbox, $row_page_info, $urlmenu_id;
  260.         
  261.     $query_top_top_menu = "select * from menu where menu_parent_menu_id = $urlmenu_id and menu_display = 1 order by menu_display_order";
  262.     $top_top_menu = mysql_query($query_top_top_menu, $eggbox) or die(mysql_error());
  263.     $row_top_top_menu = mysql_fetch_assoc($top_top_menu);
  264.     $totalRows_top_top_menu = mysql_num_rows($top_top_menu);
  265.     
  266.     if($row_page_info['page_lhs_content'] == "" && $row_page_info['page_rhs_content'] == "" && $totalRows_top_top_menu == 0) {
  267.         $collhsrhs = "-noLHSRHS";
  268.     } elseif($row_page_info['page_rhs_content'] == "" ) {
  269.         $collhsrhs = "-noRHS";
  270.     } elseif ($row_page_info['page_lhs_content'] == "" || $row_top_top_menu == 0) {
  271.         $collhsrhs = "-noLHS";
  272.     } else {
  273.         $collhsrhs = "";
  274.     }
  275.     
  276.     return $collhsrhs;
  277. }
  278. mysql_free_result($page_info);

Afficher de l'information

  • Total des messages de ce sujet: 10 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 133 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC