[Resolved] connections to another db with php include
#1
Posted 15 September 2007 - 12:40 AM
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
Posted 15 September 2007 - 01:12 AM
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
Posted 15 September 2007 - 01:25 AM
#4
Posted 08 January 2008 - 11:49 PM
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
Posted 09 January 2008 - 04:30 AM
darren, on Jan 8 2008, 06:49 PM, said:
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
Posted 09 January 2008 - 04:13 PM
<?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
Posted 09 January 2008 - 09:28 PM
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
Posted 10 January 2008 - 12:22 AM
http://dahlgren.slyip.com
http://ralphdahlgren.com
#9
Posted 10 January 2008 - 03:00 AM
#10
Posted 10 January 2008 - 02:28 PM
Cris D., on Jan 9 2008, 10:00 PM, said:
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
Posted 10 January 2008 - 09:13 PM
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...
#12
Posted 10 January 2008 - 09:19 PM
closed as no longer needed
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


This topic is locked








