SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jun 2003
    Location
    boston
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mambo php variable output question

    I'm trying to integrate the menu module into a dynamic flash menu component for MamboServer CMS sytem. Basically instead of the menu being html, it'll be flash but still dynamic so you can add and delete through the admin as usual.

    It is pretty simple if you know actionscripting but I am having trouble wih the mainmenu2.php file. I need it to output all its variables in a certain way when you access that file directly (localhost/Mambo/mainmenu2.php). Right now I get this error:

    Fatal error: Call to a member function on a non-object in /Users/home/Sites/Mambo/mainmenu2.php on line 107

    line 107 is this:

    $res = $database->openConnectionWithReturn($sqlmenu);

    if I take that statement out I get this:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Users/home/Sites/Mambo/mainmenu2.php on line 108

    Any Suggestions?

  2. #2
    Thinking about Visual Thinking
    Join Date
    May 2003
    Location
    back in South Africa
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by amana
    Right now I get this error:

    Fatal error: Call to a member function on a non-object in /Users/home/Sites/Mambo/mainmenu2.php on line 107

    line 107 is this:

    $res = $database->openConnectionWithReturn($sqlmenu);
    Just a thought ... have you initialized $database correctly? Do you have an instance of the class 'Database'?

    'Call to a member function on a non-object' just hints to these questions .

  3. #3
    SitePoint Member
    Join Date
    Jun 2003
    Location
    boston
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I must have spent 3 hours trying to figure that out. I think it is though but am not sure where it is initialized. the first two lines of the function (and file) where the variables are determined are:

    function printMenu($sublevel, $componentid, $hierarchyTree, $gid, $dbprefix, $Itemid) {
    global $database;

    and then a set of standards to grab all the variables.

    Now the only place I could find where the variable $database is mentioned is in the file classes/databae.php. This file contains this:

    <?php
    class database {
    function database(){
    include ("configuration.php");
    $link=mysql_connect($host, $user, $password);
    mysql_select_db($db) or die("Query failed with error: ".mysql_error());
    }

    function openConnectionWithReturn($query){
    $result=mysql_query($query) or die("Query failed with error: ".mysql_error());
    return $result;
    }

    function openConnectionNoReturn($query){
    mysql_query($query) or die("Query failed with error: ".mysql_error());
    }
    }
    ?>

    But I can not see where it is referenced in mainmenu2.php. I hope I'm being clear enough. Thanks

  4. #4
    Thinking about Visual Thinking
    Join Date
    May 2003
    Location
    back in South Africa
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, ...

    PHP Code:
    function printMenu($sublevel$componentid$hierarchyTree$gid$dbprefix$Itemid) {
    global 
    $database
    printMenu is apparently referencing $database as global. This variable must be initialized in the global namespace!

    Please be so kind to post the code of mainmenu2.php as well as of configuration.php (mentioned in database.php) ... would give us more insight of what is going on - hopefully .

  5. #5
    SitePoint Member
    Join Date
    Jun 2003
    Location
    boston
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sometimes all it takes is a little thought. This script is referenced by index.php which who's first lines of code are:

    require ("classes/database.php");
    $database = new database();

    Now if I had followed logic and just put this code in mainmenu2.php I wouldn't have had to go through all this!!!! I knew global $database; had to be referring to the database.php file yet I didn't think to require the script in it for like 2 days. Oh well, at least I'm learning and its working now. Thanks for your help.

  6. #6
    Thinking about Visual Thinking
    Join Date
    May 2003
    Location
    back in South Africa
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pleasure.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •