Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Include as a Var

    Im trying to use a variable that contains the Include function. But it errors

    PHP Code:
    Warning: include() [function.include]: Failed opening '' for inclusion (include_path=.;xamppphppearin C:xampphtdocsbox_right.php on line 34
    Welcome
     
    Welcome
    !
    This is just to make it look even :D

    Page generated in
    0.17449 seconds
    Welcome
    !

    Is there a way to have the include function in a variable?

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,021
    Thanks
    2
    Thanked 313 Times in 305 Posts
    Yes, but you would need to post the code you are using to get any specific help with what it is doing. It is likely that the variable was empty at the time the code was executed.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, here is my code and it works where i have it selecting from boxes but not from the include

    PHP Code:



    $sql
    "SELECT * FROM modules WHERE side = 2 ORDER BY pos";
    $query mysql_query("$sql");
      while (
    $row mysql_fetch_array($query,MYSQL_BOTH))
        {
            
    $title $row["tname"];
            
    $inc $row["include"];
            
    $content = (include("$inc"));
            
                echo 
    box("$title","$content"); 
                echo 
    "<BR>";

        };

    ?> 

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Have a look at output buffering:
    http://www.php.net/outcontrol
    PHP Code:
    <?php

    $sql 
    "SELECT * FROM modules WHERE side = 2 ORDER BY pos";
    $query mysql_query$sql );
    while ( 
    $row mysql_fetch_array$queryMYSQL_BOTH ) )
    {
        
    $title $row["tname"];
        
    $inc $row["include"];
        
    ob_start();
        include 
    $inc;
        
    $content ob_get_contents();
        
    ob_end_clean();
        echo 
    box$title$content );
        echo 
    "<BR>";
    };

    ?>
    Last edited by kbluhm; 08-15-2007 at 04:51 AM.

  • #5
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\box_right.php on line 26

    Yer it works. Its fetching the news but its not getting the second one.

    I had a look at the Output Buffering but it came up with the same error.
    Last edited by nedloh312; 08-15-2007 at 05:00 AM.

  • #6
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone?

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,021
    Thanks
    2
    Thanked 313 Times in 305 Posts
    Your latest error message means that the mysql_query(...) function call failed and returned a FALSE value instead of a result resource. Your code has no error checking and error reporting to get php/mysql to tell you why the query failed. The programming examples for the mysql_query() function in the php manual contain typical error checking logic - http://php.net/mysql_query
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #8
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, i did what you said and i made a error reported and it works now. Here is the final code


    PHP Code:
    $sql "SELECT * FROM modules WHERE side = 2 ORDER BY pos";
    $query mysql_query($sql);
    $row mysql_fetch_array$queryMYSQL_BOTH );

    while (
    $row mysql_fetch_array($query) )
    {    
    $title $row["tname"];
        
    $inc $row['include'];
        
    ob_start();
        include (
    $inc);
        
    $include ob_get_contents();
        
    ob_end_clean();

        echo 
    box$title$include);
        echo 
    "<BR>";
    };

    ?> 
    So my module system is working now. Now i just have to write some

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You shouldn't need this line: $row = mysql_fetch_array( $query, MYSQL_BOTH );

  • #10
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yer i do. That will fetch the modules as an array. Also, there is more than 1 result because its a module system.

    EDIT
    Lol, i see XD Scrap that top one lol.


  •  

    Posting Permissions

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