Jump to content


[Resolved] connections to another db with php include


  • This topic is locked This topic is locked
11 replies to this topic

#1 darren

    Likes Etomite Forums!

  • Member
  • PipPip
  • 251 posts

Posted 15 September 2007 - 12:40 AM

I've just read that Dean has used php includeds in his sites and it got me wondering what other kind of data I could bring into the eto template.
I thought I'd try bring some basic data from my forum db (same server) into a side bar area, like the latests members, recent posts etc.

I have a page called 'somethingnew.php' that outputs the desired info in a browser. yes, it works.

I created a snippet containing:
<?php include("somethingnew.php"); ?>

then place the snippet in the desired area of my template. However, i get this error message:

Parse error: parse error, unexpected '<' in ....\index.php(506) : eval()'d code on line 1

what have I missed?

#2 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 15 September 2007 - 01:12 AM

Snippets are already being read by the parser as php. Calling the include can simply be done with
include();

If you want to get data from a databse outside your etomite installation, you can also use the external APIs like getExtTableRows (see the documentation for more on these).

#3 darren

    Likes Etomite Forums!

  • Member
  • PipPip
  • 251 posts

Posted 15 September 2007 - 01:25 AM

Oh, i just love it when i overlook such basic knowledge. working now.

#4 darren

    Likes Etomite Forums!

  • Member
  • PipPip
  • 251 posts

Posted 08 January 2008 - 11:49 PM

So I'm going to revisit this now that I have a few free moments. Using the include method I can connect and output the data I want, but the include file/data is spit out above the template in etomite, not in the right column where it belongs. In the same template (outside of etomite, an .html page) that div is positioned where I want it, so i'm stuck at the point of integrating the data into the eto page.

I have the getExtTableRows function returning an Array, (see it above the content area of the same page) but I'm stuck at the point of taking that data and creating the links as they are above the page. my php skills leave much to be desired...

someone, please point me in the right direction for either method to get this information in my template. many thanks.

Edited by darren, 10 January 2008 - 09:15 PM.


#5 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 09 January 2008 - 04:30 AM

View Postdarren, on Jan 8 2008, 06:49 PM, said:

So I'm going to revisit this now that I have a few free moments. Using the include method I can connect and output the data I want, but the include file/data is spit out above the template in etomite, not in the right column where it belongs. In the same template (outside of etomite, an .html page) that div is positioned where I want it, so i'm stuck at the point of integrating the data into the eto page.

you can see it here, temporarily

I have the getExtTableRows function returning an Array, (see it above the content area of the same page) but I'm stuck at the point of taking that data and creating the links as they are above the page. my php skills leave much to be desired...

someone, please point me in the right direction for either method to get this information in my template. many thanks.

Are you using echo to display the data...??? If so then that is the problem... You cannot use echo or print functions as they bypass the output buffering that Etomite relies on for proper page rendering... This would explain why your results are being displayed above the rendered page... If you load an output variable, $output being the Etomite snippet standard, then use return $output; at the bottom of your snippet then the resulting data will be displayed in the exact location where the snippet call resides, unless it is logically positioned elsewhere using CSS...

#6 darren

    Likes Etomite Forums!

  • Member
  • PipPip
  • 251 posts

Posted 09 January 2008 - 04:13 PM

yes, the include file uses this:
 <?php do { ?>
<p><a href="forums/index.php?action=profile;u=<?php echo $row_forumnews['ID_MEMBER']; ?>"><?php echo $row_forumnews['memberName']; ?></a> 
    <?php } while ($row_forumnews = mysql_fetch_assoc($forumnews)); ?>
    

i'm confused how to use getExtTableRows- i can use it to print with 'return $output;' an array like:

Array ( [0] => Array ( [ID_MEMBER] => 47 [memberName] => PIPCCETC ) [1] => Array ( [ID_MEMBER] => 46 [memberName] => ADALLINEA ) [2] => Array ( [ID_MEMBER] => 45 [memberName] => fernando ) )

but i don't want to see that, i want to take it and bring it into some links, something like this(which does not work):
return $output;(<a href="forums/index.php?action=profile;u=$row_forumnews['ID_MEMBER']">$row_forumnews['memberName']</a>);

thanks for your help!

Edited by darren, 09 January 2008 - 06:10 PM.


#7 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 09 January 2008 - 09:28 PM

Think of the output buffer as a long string that you "build" in a factory. Then when you use "return", the string is shipped out.

In your snippet, you don't need <?php (in most cases) as the code is already being read as php.
Instead of echo, use $output .= and concatenate (or join) your string where necessary with periods.
Notice also that I used single quotes' ' instead of double quotes"" for the html, this stops the need for escaping them.
Therefore, your code above will now be...
do {
$output .='<p><a href='forums/index.php?action=profile;u=' ';
$output .=$row_forumnews['ID_MEMBER'] . $row_forumnews['memberName'];
$output .='</a>';
	 } while ($row_forumnews = mysql_fetch_assoc($forumnews));

return $output;
Of course, there is about another 20 ways to write this using various methods all with advantages and disadvantages...

As for displaying the data, try Ralph's tutorials, and the mergeCodeVariables is very good at handling this.
Psudo code: first gather your resources (data and how you want it displayed).

DATA
$rs= $etomite->getExtTableRows();
which will return this:
Array ( [0] => Array ( [ID_MEMBER] => 47 [memberName] => PIPCCETC ) [1] => Array ( [ID_MEMBER] => 46 [memberName] => ADALLINEA ) [2] => Array ( [ID_MEMBER] => 45 [memberName] => fernando ) )

How you want it displayed using placeholders{} to use for the API to insert the rows data:
$chunk=
<<<END
<a href="forums/index.php?action=profile&u={ID_MEMBER}">{MEMBER_NAME}</a>
END;

Then run
$output=
$etomite->mergeCodeVariables($chunk,$rs,$prefix="{",$suffix="}",$oddStyle="",$evenStyle="",$tag="");
return $output;

Or if you want to handle it manually for a single row...

$output .='<a href='forums/index.php?action=profile&u=';
$output .=$rs[0]['ID_MEMBER'];
$output .='>'.$rs[0]['MEMBER_NAME'].'</a>';
return $output;

Or for multiple records, use a loop like your do...while, or for or foreach etc substituting the $rs[0] for the incremental value like $rs[$i]['MEMBER_ID'], see php.net for more on this.

Edited by Cris D., 09 January 2008 - 09:50 PM.


#8 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 10 January 2008 - 12:22 AM

See my personal development websites for information on how to work with internal and external data... I have a thing for data and templating tutorials... They all make heavy use of the various Etomite API functions...

http://dahlgren.slyip.com
http://ralphdahlgren.com

#9 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 10 January 2008 - 03:00 AM

Nice new site Ralph. However, before anyone goes off and starts trying to get your parseChunk tutorial working, don't forget that it has not been released yet and is due to come out in 0.6.1.5

#10 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 10 January 2008 - 02:28 PM

View PostCris D., on Jan 9 2008, 10:00 PM, said:

Nice new site Ralph. However, before anyone goes off and starts trying to get your parseChunk tutorial working, don't forget that it has not been released yet and is due to come out in 0.6.1.5


You are correct, and I think I have it mentioned in the text, along with a copy of the modified API function... The new parseChunk example is just one of many, although posibly the only one on the ralphdahlgren.com site...

#11 darren

    Likes Etomite Forums!

  • Member
  • PipPip
  • 251 posts

Posted 10 January 2008 - 09:13 PM

got it working. i put the contents of the included file into a snippet so everything could be viewed at once and fiddled with the output lines a bit. this is what it ended up being:

do {
$output .=('<p><a href="forums/index.php?action=profile;u=');
$output .=$row_forumnews['ID_MEMBER'];
$output .=('">');
$output .=$row_forumnews['memberName'];
$output .=('</a></p>');
     } while ($row_forumnews = mysql_fetch_assoc($forumnews));

return $output;

maybe there's logically a better way to do it, but it's working so I don't want to touch it!
You guys are most helpful... :D

#12 Dean

    Loves Etomite Forums!

  • Admin
  • 4,758 posts
  • Gender:Male

Posted 10 January 2008 - 09:19 PM

Glad you got it sorted!

closed as no longer needed





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users