...

View Full Version : Include as a Var



nedloh312
08-15-2007, 05:25 AM
Im trying to use a variable that contains the Include function. But it errors



Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.;\xampp\php\pear\') in C:\xampp\htdocs\box_right.php on line 34
Welcome

Welcome!
This is just to make it look even :D

Page generated in: 0.17449 seconds
Welcome!
1


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

CFMaBiSmAd
08-15-2007, 05:28 AM
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.

nedloh312
08-15-2007, 05:32 AM
Well, here is my code and it works where i have it selecting from boxes but not from the include






$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>";

};

?>

kbluhm
08-15-2007, 05:42 AM
Have a look at output buffering:
http://www.php.net/outcontrol

<?php

$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"];
ob_start();
include $inc;
$content = ob_get_contents();
ob_end_clean();
echo box( $title, $content );
echo "<BR>";
};

?>

nedloh312
08-15-2007, 05:48 AM
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.

nedloh312
08-15-2007, 01:29 PM
Anyone?

CFMaBiSmAd
08-15-2007, 02:04 PM
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

nedloh312
08-16-2007, 07:35 AM
Well, i did what you said and i made a error reported and it works now. Here is the final code ;)




$sql = "SELECT * FROM modules WHERE side = 2 ORDER BY pos";
$query = mysql_query($sql);
$row = mysql_fetch_array( $query, MYSQL_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 :D

Inigoesdr
08-16-2007, 10:08 PM
You shouldn't need this line: $row = mysql_fetch_array( $query, MYSQL_BOTH );

nedloh312
08-17-2007, 01:01 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum