**fixed**in need of php include file help**fixed**

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

**fixed**in need of php include file help**fixed**

Post by Obadiah »

i dont know if this can be done....especially the way that I am handling my code...I have tried several methods of including....right now my page is all css ran with all divs..and im wanting to take and display a php page within the content div...here is what i got

Code: Select all

<?php
$display_block .="
<div id=\"container\">
<div class=\"header\">
<div id=\"nest_buttons\">
<div><a class=\"home\" href=\"\"><span class=\"alt\"></span></a></div>
<div><a class=\"webmail\" href=\"\"><span class=\"alt\"></span></a></div>
<div><a class=\"Tickets\" href=\"\"><span class=\"alt\"></span></a></div>
<div><a class=\"AD\" href=\"\"><span class=\"alt\"></span></a></div>
<div><a class=\"Logout\" href=\"index.php?action=logout\"><span class=\"alt\"></span></a></div>";

$display_block .="
</div>
<div class=\"line\"><span class=\"alt\"></span></div>
<div class=\"content_back\">
<div class=\"o_text\">
";
$conn = doDB();
$sql = "Select fusername FROM users WHERE user_id = '{$_SESSION['logname']}'";
$result = mysql_query($sql,$conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result))
{
	$name= $newArray['fusername'];
}
$display_block .="
<p>Welcome: $name</p>
Options
<ul>
<li><a href=\"password_update2.php\" class=\"rolls\">Change Password</a></li>
<li><a href=\"schedule.php\" class=\"rolls\">Check Schedule</a></li>
<li><a href=\"view.php\" class=\"rolls\">View notes</a></li>
</ul>
</div>
<div class=\"c_text\">
//<?php include("header.php"); ?>//gives a parse/include error
//<!--#include virtual="insertthisfile.html" --> //also gives a parse/include error
</div>
</div>
<div class=\"footer\"> </div>
</div>
?>
<html>
<head>
<meta http-equiv="pragma" content="no-cache"/>
<title>KDMC - Welcome to IS Helpweb</title>
<link href="ostyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>
Last edited by Obadiah on Sun Apr 04, 2010 4:15 pm, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: in need of php include file help

Post by Christopher »

You can include a file in the middle of a string. And you need to close your strings with an end quote (i.e., if you start with $display_block .=" you need to end with "; ).

If you want the include file to append to the string the put a $display_block .="..."; inside it, or use the output buffering methods to capture the output into a string.
(#10850)
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Re: in need of php include file help

Post by Obadiah »

im sorry about the confusion...here is what I should have posted...i have tried

Code: Select all

<?php
$display_block .="
<p>Welcome: $name</p>
Options
<ul>
<li><a href=\"password_update2.php\" class=\"rolls\">Change Password</a></li>
<li><a href=\"schedule.php\" class=\"rolls\">Check Schedule</a></li>
<li><a href=\"view.php\" class=\"rolls\">View notes</a></li>
</ul>
</div>
<div class=\"c_text\">";
//gives the error Parse error: syntax error, unexpected T_STRING in C:\xampp\home.php on line 54
$display_block.="<?php include("folder/example.php"); ?>";//line54
$display_block .="
</div>
</div>
<div class=\"footer\"> </div>
</div>
";
?>
where is the parse error coming from?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: in need of php include file help

Post by Christopher »

In order to reply I would just need to post my previous comment again. Please read it carefully.
(#10850)
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Re: in need of php include file help

Post by Obadiah »

thanks chris but i have tried this and have posted it back, is the $display_block .="..."; wrong
Christopher wrote:You can include a file in the middle of a string. And you need to close your strings with an end quote (i.e., if you start with $display_block .=" you need to end with "; ).
and are you sugessting that I use another method here...if so can you show me an example because when i use the include inside or outside the display block I get the parse error. if I paste the contents of the file outside of the file i want to inclue it gives me a parse error until i remove the begining and closing php tags...then it actually works...but the information is not inside of the <div> tag I placed it between and it begins to echo out code the code under it.
can you show me an example of what you mean here if what i have tried is not what you are mentioning here?
Christopher wrote: If you want the include file to append to the string the put a $display_block .="..."; inside it, or use the output buffering methods to capture the output into a string.
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Re: in need of php include file help

Post by Obadiah »

i dont know if this matters or not but the file that i am trying to include is a excelreader file that is already working...now i got it to either say that it cant read the file when i get rid of the parse errors...so i did this

Code: Select all

<?php
session_start();
function doDB()
{
	$conn = mysql_connect("localhost","root","") or die(mysql_error());
	mysql_select_db("helpdata",$conn) or die(mysql_error());
	return $conn;
}

function clearsessionscookies() 
{ 
    unset($_SESSION['auth']); 
    unset($_SESSION['logname']); 
	$_COOKIE[auth]=="0";
    session_unset();     
    session_destroy();
     
}

require_once 'calls\excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("calls\book1.xls");

$display_block .="
<div id=\"container\">
<div class=\"header\">
<div id=\"nest_buttons\">
<div><a class=\"home\" href=\"\"><span class=\"alt\"></span></a></div>
<div><a class=\"webmail\" href=\"\"><span class=\"alt\"></span></a></div>
<div><a class=\"Tickets\" href=\"\"><span class=\"alt\"></span></a></div>
<div><a class=\"AD\" href=\"\"><span class=\"alt\"></span></a></div>
<div><a class=\"Logout\" href=\"index.php?action=logout\"><span class=\"alt\"></span></a></div>";

$display_block .="
</div>
<div class=\"line\"><span class=\"alt\"></span></div>
<div class=\"content_back\">
<div class=\"o_text\">
";
$conn = doDB();
$sql = "Select fusername FROM users WHERE user_id = '{$_SESSION['logname']}'";
$result = mysql_query($sql,$conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result))
{
	$name= $newArray['fusername'];
}
$display_block .="
<p>Welcome: $name</p>
Options
<ul>
<li><a href=\"password_update2.php\" class=\"rolls\">Change Password</a></li>
<li><a href=\"schedule.php\" class=\"rolls\">Check Schedule</a></li>
<li><a href=\"view.php\" class=\"rolls\">View notes</a></li>
</ul>
</div>
<div class=\"c_text\">
<?php echo $data->dump(true,true); ?>//it doesnt work here
</div>
</div>
<div class=\"footer\"> </div>
</div>
";

/*if (isset($_COOKIE[session_name()]) && isset($_GET['action']) && 'logout'===$_GET['action'] ) { 
	
	setcookie(session_name(), '', time()-42000, '/');
	//destroy the session
	if(!empty($_SESSION))
	{
        session_destroy();
	}

	//set session to an empty array
	$_SESSION = array();
	clearsessionscookies(); 
        
       
}*/ 
?>

<html>
<head>
<meta http-equiv="pragma" content="no-cache"/>
<title>KDMC - Welcome to IS Helpweb</title>
<link href="ostyle.css" rel="stylesheet" type="text/css">
<style>
table.excel {
	border-style:ridge;
	border-width:1;
	border-collapse:collapse;
	font-family:sans-serif;
	font-size:12px;
}
table.excel thead th, table.excel tbody th {
	background:#CCCCCC;
	border-style:ridge;
	border-width:1;
	text-align: center;
	vertical-align:bottom;
}
table.excel tbody th {
	text-align:center;
	width:20px;
}
table.excel tbody td {
	vertical-align:bottom;
}
table.excel tbody td {
    padding: 0 3px;
	border: 1px solid #EEEEEE;
}
</style>
</head>
<body>
<?php echo $display_block; ?>
<?php echo $data->dump(true,true); ?>//or here
</body>
</html>
now say if I use the include("the filename.php"); it will say that the xls file cannot be read. however it doesnt work at all the other way
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Re: **fixed**in need of php include file help**fixed**

Post by Obadiah »

i decided to just go with a no border iframe
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: in need of php include file help

Post by Christopher »

Obadiah wrote:If you want the include file to append to the string the put a $display_block .="..."; inside it, or use the output buffering methods to capture the output into a string.
[/quote]
Either do $display_block .=" inside "folder/example.php" or wrap the include in output buffering methods like this:

Code: Select all

ob_start()
include("folder/example.php");
$display_block .= ob_get_flush();
(#10850)
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Re: in need of php include file help

Post by Obadiah »

Christopher wrote:
Obadiah wrote:If you want the include file to append to the string the put a $display_block .="..."; inside it, or use the output buffering methods to capture the output into a string.
Either do $display_block .=" inside "folder/example.php" or wrap the include in output buffering methods like this:

Code: Select all

ob_start()
include("folder/example.php");
$display_block .= ob_get_flush();
[/quote]


thanks bro...i will try this out...sorry about the late reply
Post Reply