SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict eddiembabaali's Avatar
    Join Date
    Mar 2001
    Location
    USA, Philadelphia
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php BUG exterminator needed

    I am tryng to write a small function that will extract pagecontent from a database and i am having problems with it.

    I have checked and the dbconnect function, dbselect function are all working fine. Here is the code

    PHP Code:

    #
    #Function for getting page content from database
    function pagecontent($filename) {
        include (
    "config.php");
    dbconnect();
    dbselect("$dbname");
    $sql=mysql_query("SELECT * FROM sitecontent WHERE filename='$filename'");
     
    $row mysql_fetch_array($sql);
     
    $pid=$row["pid"];
     
    $pagetitle=$row["pagetitle"];
     
    $bodytext=$row["bodytext"];
     
    $section=$row["section"];
     
    $pageheading=$row["pageheading"];
     
    $filename=$row["filename"];

    return 
    $pagetitle;
    return 
    $bodytext;
    return 
    $section;
    return 
    $pageheading;
    return 
    $filename;

     }
    // end function getpagecontent 
    I want to call this function at the top of each page and supply a filename like this

    PHP Code:
    pagecontent("homepage");
    echo 
    "$bodytext";
    echo
    "<h4>$pageheading</h4>"
    The code stops to work only when I make it a function ..I really would not like to write all that code at the beginning of each page .. Any ideas why these values will not get returned by the function ?

    Thanks in advance
    cd pub \r; more beer

    Eddie

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you can't return multiple items from a function, unless you return an array.

    PHP Code:
    #
    #Function for getting page content from database
    function pagecontent($filename) {
        include (
    "config.php");
    dbconnect();
    dbselect("$dbname");
    $sql=mysql_query("SELECT * FROM sitecontent WHERE filename='$filename'");
     return 
    mysql_fetch_array($sql);
     }
    // end function getpagecontent

    $pc pagecontent("homepage");
    echo 
    $pc['bodytext'];
    echo 
    "<h4>".$pc['pageheading']."</h4>"
    You could do this though
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm not entirely familiar with PHP but you usually can't make a function return multiple times... only 1 object can be returned from a function so i guess that's where your code went wrong...

    see you didn't actually need a PHP bug exterminator...

  4. #4
    SitePoint Addict eddiembabaali's Avatar
    Join Date
    Mar 2001
    Location
    USA, Philadelphia
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a bunch Freddy. I was getting desperate and entered all those returns... Its all working well now you are my hero!
    cd pub \r; more beer

    Eddie


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
  •