Jump to content

insert include function in a variable ?


Alicia

Recommended Posts

Hi,

 

I would like to display content of a php file by using include in the following script. Can some gurus advise what I can do to accomplish this :

 


$ret .='
<div id="main_bar_bottom">

<div align="center">
<div class="para"  id="1" style="display:none;">
<div class="tab_full_box">
<a href="'.ProfL($ID).'"><img src="'.$site['url'].'hat.gif" align="absmiddle" border="0"/><img src="'.$site['url'].'hat.gif" align="absmiddle" border="0"/>'.INCLUDE PHP file here.'</a>
</div>
</div></div>';

 

I tried to put include"file.php"; in the INCLUDE PHP file here part of the script but error occured.

 

PLease advise, THanks.

Link to comment
Share on other sites

function parseinc($file) {
  ob_start()
  include $file;
  return ob_end_clean();
}

$ret .='
<div id="main_bar_bottom">

<div align="center">
<div class="para"  id="1" style="display:none;">
<div class="tab_full_box">
<a href="'.ProfL($ID).'"><img src="'.$site['url'].'hat.gif" align="absmiddle" border="0"/><img src="'.$site['url'].'hat.gif" align="absmiddle" border="0"/>'.parseinc('yourfile.php').'</a>
</div>
</div></div>';

Link to comment
Share on other sites

What is in your included file?

Here is an example of what is possible

main.php

echo 'OMG I AM INCLUDING SOME LINKS HERE PLEASE SEE BELOW.<br/>' . include('theotherfile.php');

 

theotherfile.php

<?php 
return '<a href="">Link 1</a><br/><a href="">Link 2</a>';
?>

this is only 1 example of the include usage and it will fit your method depending on the contents of the other file of course...

Link to comment
Share on other sites

my file to display the content :

 

<?php
$memberID = (int)$_COOKIE['memberID'];
$memberPassword = $_COOKIE['memberPassword'];

function getActivityBarTopGKC()
{
global $memberID;
global $activity_bar_hide_gkc;

if($memberID)
  {
   if($activity_bar_hide_gkc!='1')
     {
        $ret = getActivityBarTop();
        return $ret;
     }
  }

}

function getActivityBarFooterDiv()
{
global $memberID;

if($memberID)
{
   $ret = '<div style="height:40px"></div>';
   return $ret; }

}


function getActivityBarTop()
{
global $dir;
global $site;
global $memberID;
        global $memberPassword;
        global $block_online_friends_thumbs;


// friend online START

$id = $memberID;
/*
$friend_list_query = "SELECT `Profiles`.* FROM `FriendList`
							 LEFT JOIN `Profiles` ON (`Profiles`.`ID` = `FriendList`.`Profile` AND `FriendList`.`ID` = '$id' OR `Profiles`.`ID` = `FriendList`.`ID` AND `FriendList`.`Profile` = '$id')
							 WHERE (`FriendList`.`Profile` = '$id' OR `FriendList`.`ID` = '$id') AND `FriendList`.`Check` = '1' ORDER BY `Profiles`.`NickName` ASC";
							 */

$friend_list_query = "SELECT `Profiles`.* FROM `FriendList`
							 LEFT JOIN `Profiles` ON (`Profiles`.`ID` = `FriendList`.`Profile` AND `FriendList`.`ID` = '$id' OR `Profiles`.`ID` = `FriendList`.`ID` AND `FriendList`.`Profile` = '$id')
							 WHERE (`FriendList`.`Profile` = '$id' OR `FriendList`.`ID` = '$id') AND `FriendList`.`Check` = '1' ORDER BY `Profiles`.`NickName` ASC";

$friend_list_res = db_res("$friend_list_query");

        $onfrnds = 0;
        $num='0';
        $numnick='0';

        $retfrndsonlinebigthumb = '<table width="940" border="0" cellspacing="0" cellpadding="4">';

        $retfrndsonlinenothumb = '<table width="940" border="0" cellspacing="0" cellpadding="4">';

        $retfrndsonlinenothumbsmall = '<table width="940" border="0" cellspacing="0" cellpadding="4">';


while ( $friend_list_arr = mysql_fetch_assoc( $friend_list_res ) )
{
$onlinefrndsgkc = get_user_online_status( $friend_list_arr['ID']);
if($onlinefrndsgkc=='1')
{
      $onfrnds ++;
      $num ++;
      $numnick ++;
      $endtrover= '0';
      $endtrovernick= '0';

     if($num=='1')
      { $retfrndsonlinebigthumb .= "<tr>"; }
     if($numnick=='1')
      { $retfrndsonlinenothumb .= "<tr>";
        $retfrndsonlinenothumbsmall .= "<tr>"; }


$retfrndsonlinebigthumb .= '<td class="friend_block" style="width:210px">
<a href="' . getProfileLink($friend_list_arr['ID']) . '" title="' . $friend_list_arr['NickName'] . '"><font style="font-weight:bold">' . $friend_list_arr['NickName'] . '</font></a><br/>
'.get_member_icon( $friend_list_arr['ID'],'left' ).' <a href="javascript:void(0);" onClick="javascript:window.open( \''.$site['url'].'ray/index.php?module=im&app=user&sender='.$memberID.'&password='.$memberPassword.'&recipient='.$friend_list_arr['ID'].'\', \'\', \'width=600,height=600,menubar=no,status=no,resizable=yes,scrollbars=yes,toolbar=no, location=no\' );" title="'._t( "_Activity_bar IM Now" ).'"><img src="'.$site['url'].'activitybar/chat.gif" height="18" width="18" border="0" alt="'._t( "_Activity_bar IM Now" ).'"> '._t( "_Activity_bar IM Now" ).'</a>
<br/> <a href="'.$site['url'].'compose.php?ID='.$friend_list_arr['ID'].'" title="'._t( "_Activity_bar Message" ).'"><img src="'.$site['url'].'activitybar/message.gif" border="0" alt="'._t( "_Activity_bar Message" ).'" height="18" width="18"> '._t( "_Activity_bar Message" ).'</a>
</td>';

$retfrndsonlinenothumb .= '<td class="friend_block" style="width:134px">
<center><a href="' . getProfileLink($friend_list_arr['ID']) . '" title="' . $friend_list_arr['NickName'] . '"><font style="font-weight:bold">' . $friend_list_arr['NickName'] . '</font></a><br/>
<a href="javascript:void(0);" onClick="javascript:window.open( \''.$site['url'].'ray/index.php?module=im&app=user&sender='.$memberID.'&password='.$memberPassword.'&recipient='.$friend_list_arr['ID'].'\', \'\', \'width=600,height=600,menubar=no,status=no,resizable=yes,scrollbars=yes,toolbar=no, location=no\' );" title="'._t( "_Activity_bar IM Now" ).'"><img src="'.$site['url'].'activitybar/chat.gif" height="18" width="18" border="0" alt="'._t( "_Activity_bar IM Now" ).'"> '._t( "_Activity_bar IM Now" ).'</a>
<br/><a href="'.$site['url'].'compose.php?ID='.$friend_list_arr['ID'].'" title="'._t( "_Activity_bar Message" ).'"><img src="'.$site['url'].'activitybar/message.gif" border="0" alt="'._t( "_Activity_bar Message" ).'" height="18" width="18"> '._t( "_Activity_bar Message" ).'</a></center>
</td>';

$retfrndsonlinenothumbsmall .= '<td class="friend_block" style="width:134px">
<center><a href="' . getProfileLink($friend_list_arr['ID']) . '" title="' . $friend_list_arr['NickName'] . '"><font style="font-weight:bold">' . $friend_list_arr['NickName'] . '</font></a><br/>
<a href="javascript:void(0);" onClick="javascript:window.open( \''.$site['url'].'ray/index.php?module=im&app=user&sender='.$memberID.'&password='.$memberPassword.'&recipient='.$friend_list_arr['ID'].'\', \'\', \'width=600,height=600,menubar=no,status=no,resizable=yes,scrollbars=yes,toolbar=no, location=no\' );" title="'._t( "_Activity_bar IM Now" ).'"><img src="'.$site['url'].'activitybar/chat.gif" height="18" width="18" border="0" alt="'._t( "_Activity_bar IM Now" ).'"></a>
  <a href="'.$site['url'].'compose.php?ID='.$friend_list_arr['ID'].'" title="'._t( "_Activity_bar Message" ).'"><img src="'.$site['url'].'activitybar/message.gif" border="0" alt="'._t( "_Activity_bar Message" ).'" height="18" width="18"></a></center>
</td>';

  if($num=='4')
  {
    $retfrndsonlinebigthumb .= '</tr>';
    $num='0';
    $endtrover= '1';
  }
  if($numnick=='7')
  {
    $retfrndsonlinenothumb .= '</tr>';
    $retfrndsonlinenothumbsmall .= '</tr>';
    $numnick='0';
    $endtrovernick= '1';
  }
  else
  { $endtrover= '0';
    $endtrovernick= '0'; }

}
}

if($endtrover=='0')
{
   $retfrndsonlinebigthumb .= '</tr>';
}

if($endtrovernick=='0')
{
   $retfrndsonlinenothumb .= '</tr>';
   $retfrndsonlinenothumbsmall .= '</tr>';
}

if($onfrnds=='0')
   {
      $retfrndsonlinebigthumb .= '<div><img src="'.$site['url'].'activitybar/info.gif"/> '._t( "_Activity_bar No friend Online" ).'</div>';
      $retfrndsonlinenothumb .= '<div><img src="'.$site['url'].'activitybar/info.gif"/> '._t( "_Activity_bar No friend Online" ).'</div>';
      $retfrndsonlinenothumbsmall .= '<div><img src="'.$site['url'].'activitybar/info.gif"/> '._t( "_Activity_bar No friend Online" ).'</div>';
   }

$retfrndsonlinebigthumb .= '</table>';
$retfrndsonlinenothumb .= '</table>';
$retfrndsonlinenothumbsmall .= '</table>';

if( $onfrnds < '5' )
{
   if($block_online_friends_thumbs=='1')
    {
     $onlineFriendsListNicknames .= $retfrndsonlinebigthumb;
    }
   else
    {
     $onlineFriendsListNicknames .= $retfrndsonlinenothumb;
    }
}
elseif( $onfrnds < '8' )
{
  $onlineFriendsListNicknames .= $retfrndsonlinenothumb;
}
else
{
  $onlineFriendsListNicknames .= $retfrndsonlinenothumbsmall;
}


if($onfrnds!='0')
{
   $onlinefrndnum = '<strong>'.$onfrnds.'</strong>';
}
else
{
   $onlinefrndnum = $onfrnds;
}


// friend online END
function parseinc($file) {
  ob_start();
  include $file;
  return ob_end_clean();
}	

$ret .='

<script type="text/javascript">


var blocks_array = new Array("1","2","3","4","5"); 

function display_blocks(block_id)
{
  if (document.getElementById(block_id).style.display=="")
  {
   document.getElementById(block_id).style.display = "none";
   return;
  }
for (i=0; i<blocks_array.length;i++)
  {
   var blocks = document.getElementById(blocks_array[i]);
   blocks.style.display = "none";
  }
  document.getElementById(block_id).style.display = "";
}
</script>



<div id="main_bar_bottom">

<div align="center">
<div class="para"  id="1" style="display:none;">
<div class="tab_full_box">
<div class="tab_full_box_heading">
'._t( "_Activity_bar Profile" ).' (<a href="javascript:void(0)" class="headings" onClick="display_blocks(\'1\')" onFocus="if(this.blur)this.blur()";>Close</a>)</div>

<a href="'.getProfileLink($memberID).'"><img src="'.$site['url'].'activitybar/bullet.gif" align="absmiddle" border="0"/> '._t( "_Activity_bar View my Profile" ).'</a><br/>
<a href="'.$site['url'].'pedit.php?ID='.$memberID.'"><img src="'.$site['url'].'activitybar/bullet.gif" align="absmiddle" border="0"/> '._t( "_Activity_bar Edit my Profile" ).'</a>
</div>
</div>
    </td>

  </tr>
</table></div>
</div></div>
</div>

';

 

Now I want to replace this part content - _t( "_Activity_bar View my Profile" ) by printing the output generated from a php file.

 

code for the file that i want to include into the position where the text above located :

 

<?
//session_start();
include "db.php";
?>
<?
$srt1 = mysql_query("SELECT * FROM `Profiles` WHERE `Nickname`= '{$_SESSION['username']}'") or die(mysql_error());
$srt2 = mysql_fetch_array($srt1);
$srrt1 = mysql_query("SELECT * FROM `f_chat_users` WHERE `chat_user_id`= '{$srt2['ID']}'") or die(mysql_error());
$srrt2 = mysql_fetch_array($srrt1);
if($srrt2['chat_user_status'] == '1')
{
$stat = "Online";

// fchat
//------------


//-------------

}
else
{
$stat = "Offline";
}
?>

<body>

<div class="mainwrapper">


<div id="content">

	<div class="min-width">
  <?php
  
  $sqtt =mysql_query("SELECT NULL FROM f_chat_users WHERE chat_user_status != '0' AND `chat_user_id` !='0' AND `chat_user_id` != '{$srt2['ID']}' ");
   $ssq=mysql_num_rows($sqtt);
   if ($ssq>0)
   {
/*
	Place code to connect to your DB here.
*/


$tbl_name="f_chat_users";		//your table name
// How many adjacent pages should be shown on each side?
$adjacents = 1;

/* 
   First get total number of rows in data table. 
   If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE chat_user_status != '0'";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];

//echo $total_pages ." pages <br>";

/* Setup vars for query. */
$targetpage = "im_user.php"; 	//your file name  (the name of this file)
$limit = 10; 								//how many items to show per page
$page = $_GET['page'];
if($page) 
	$start = ($page - 1) * $limit; 			//first item to display on this page
else
	$start = 0;								//if no page var is given, set start to 0

/* Get data. */
     $result = mysql_query("SELECT * FROM `Profiles` where `Nickname` = '{$_SESSION['username']}'"); 
$row = mysql_fetch_array($result);
$result2 = mysql_query("SELECT * FROM `im_rate` where `userID` = '{$row['ID']}'"); 

//	$st =mysql_query("SELECT * FROM `f_chat_users` WHERE `chat_user_status` != '0' AND `chat_user_id` != '0'  AND `chat_user_id` != '{$row['ID']}' LIMIT $start,$limit");
$st =mysql_query("SELECT * FROM `f_chat_users` WHERE `chat_user_status` != '0' AND `chat_user_id` != '0'  AND `chat_user_id` != '{$row['ID']}'");

    

//$sql = "SELECT * FROM $tbl_name LIMIT $start,$limit";
//$result = mysql_query($view_query);

// echo $limit ." per page<br><br>";

/* Setup page vars for display. */
if ($page == 0) $page = 1;					//if no page var is given, default to 1.
$prev = $page - 1;							//previous page is page - 1
$next = $page + 1;							//next page is page + 1
$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;						//last page minus 1

/* 
	Now we apply our rules and draw the pagination object. 
	We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{	
	$pagination .= "<div class=\"pagination\">";
	//previous button
	if ($page > 1) 
		$pagination.= "<a href=\"$targetpage?page=$prev\">« previous</a>";
	else
		$pagination.= "<span class=\"disabled\">« previous</span>";	

	//pages	
	if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
	{	
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page)
				$pagination.= "<span class=\"current\">$counter</span>";
			else
				$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
		}
	}
	elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
	{
		//close to beginning; only hide later pages
		if($page < 1 + ($adjacents * 2))		
		{
			for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
		}
		//in middle; hide some front and some back
		elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
		}
		//close to end; only hide early pages
		else
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
		}
	}

	//next button
	if ($page < $counter - 1) 
		$pagination.= "<a href=\"$targetpage?page=$next\">next »</a>";
	else
		$pagination.= "<span class=\"disabled\">next »</span>";
	$pagination.= "</div>\n";		
}
?>



	  <table width="100%" border="0" cellspacing="5" cellpadding="0">
            
  
        <?php
	$i=1;
	$xx = 0;
	while($st2 = mysql_fetch_array($st))
	{
        $sr1 = mysql_query("SELECT * FROM `Profiles` WHERE `ID` = '{$st2['chat_user_id']}' ") or die(mysql_error());
	$sr2 = mysql_fetch_array($sr1);
	if($xx == 0) { echo "<tr>";}
	?> 
        
          <td width="80" align="center" valign="top">
          <?
           $myimage = mysql_query("SELECT * FROM `media` WHERE `med_prof_id` = '{$sr2['ID']}' AND `med_id`='{$sr2['PrimPhoto']}'") or die(mysql_error());
	   $myimage2 = mysql_fetch_array($myimage);
	  if ($myimage2['med_file'] != "")
          {
	  ?>
          <img src="media/images/profile/<? echo $sr2['ID']; ?>/icon_<? echo $myimage2['med_file']; ?>"  />          
          <? } 
	  else
	  {
	  ?>
           <img src="images/icon_man.jpg"  />   
          <? } ?>          </td>
          <td width="80" align="left">
          <a href="member_profile.php?ID=<? echo $sr2['ID']; ?>"><? echo $sr2['NickName']; ?></a><?php 
	  $mob = mysql_query("SELECT device FROM f_chat_users WHERE chat_user_id='{$sr2['ID']}'");
	  $mob2 = mysql_fetch_array($mob);
	  if($mob2['device'] == 'm'){?> <img src="mobile/images/phone.jpg"/><?php } ?><br>
          <a href="im.php?sendID=<? echo $sr2['ID']; ?>" target="_blank">IM me now!<br />
          </a><a href="invite-oovoo.php?to=<? echo $sr2['ID'];?>" target="_blank">Invite ooVoo Chat</a>          </td>
        
          <?
	  $xx++;
	  if($xx == 6) { 
echo "</tr>"; // Close off row after third entry
$xx = 0; }

	   } ?>
            
                      </table>
          <?
          }

	  ?>
      </div>
</div>

</div>

Link to comment
Share on other sites

Again I'll say it. Post your actual code!!!!

 

In your very first post your said....

 

I tried to put include"file.php"; in the INCLUDE PHP file here part of the script but error occured.

 

Post the code where you tried this, and a description of the error.

Link to comment
Share on other sites

When you try something and it doesn't work, if your going to come here and ask a question about it, you should also post the code that didn't work.

 

3 times I have asked you to provide this code, 3 times you have avoided doing so.

 

If you don't want help, don't ask. If you do, post the relevant and problematic code.

Link to comment
Share on other sites

You will need to replace all the 'echo' calls in your including page with $ret .= and then include the file in the correct position.. Its gonna be messy tho as you have tables and all sorts of things that are going to be wrapped in an <a> tag... Not pretty..

$ret .= '<a href="'.getProfileLink($memberID).'"><img src="'.$site['url'].'activitybar/bullet.gif" align="absmiddle" border="0"/> ';
include('yourfile.php'); // which has more things to append to $ret;
$ret .= '</a><br/>';

 

Edit: Not just your echo's, EVERYTHING that could possibly output from that page needs to be added to the $ret var and if you dont WANT something output you need to remove it completely..

Link to comment
Share on other sites

Hi Thorpe, I have pasted all the code on top. I am not sure why you keep on saying I didn't post it.hmm..

 

Yes masterAce, that is the line I am talking about. I added this function :

========================

function parseinc($file) {

  ob_start();

  include $file;

  return ob_end_clean();

}

========================

 

then replace '._t( "_Activity_bar View my Profile" ).'  with '.parseinc('im_user6.php').'

 

but it only show 1 which is not the output I am expecting. =(

 

 

Buddski, I have combination of php and html. It will be a nightmare if I replace it all with echo or ret. Any better to do it? I tried to insert the scripts from the other file into the section mentioned but the output shows on top of the page not in div. =(

 

Please advise and thanks,

Link to comment
Share on other sites

There is no other way the reason it is coming up at the top of the page is because you have raw output which isnt being appended to the $ret variable.. you also have a body tag in there that will be a nightmare for your CSS aswell..

 

If you want an include file to be added to a variable (which you do) you either have to do as I described before or the return method I explained earlier.. Sorry to be the bearer of bad news..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.