Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: ziycon - tammikuu 11, 2006, 11:41:59 AP

Otsikko: Site query to DB?
Kirjoitti: ziycon - tammikuu 11, 2006, 11:41:59 AP
Ive searched and cant find it.
But does anyone know how to query the database from a website to publish a list of users online in the chat forum onto a php website????
Otsikko: Re: Site query to DB?
Kirjoitti: Leipe Po - tammikuu 11, 2006, 11:44:19 AP
http://www.simplemachines.org/community/ssi_examples.php

try taking a look there, think its ssi_logonline() and/or ssi_usersonline or somthing
Otsikko: Re: Site query to DB?
Kirjoitti: ziycon - tammikuu 11, 2006, 11:54:02 AP
i found it on that page thanks, i need to add this to my php page:

<?php require("SSI.php"); ?>

say that file is kept some were like here:

www.domainname.com/forum/SSI.php

how do i referance it?
Otsikko: Re: Site query to DB?
Kirjoitti: ziycon - tammikuu 11, 2006, 12:08:41 IP
I have referanced in such a way that i get a message at top of the site:

Please don't access SSI.php by URL directly; you may want to use the path ('SSI.php') or add ?ssi_function=something.

Can anyone help with this please?
Otsikko: Re: Site query to DB?
Kirjoitti: Leipe Po - tammikuu 11, 2006, 12:24:06 IP
wel if you use header and footer, open your header and add at the verry first line!!!
<?php require("forum/SSI.php"); ?>

if not, you will have to add that code above to every file you want to use ssi on

and then where you want the online list to show up:
<?php ssi_whosOnline(); ?>

or if you also want them logged:
<?php ssi_logOnline(); ?>

Greetz Leipe_Po

Otsikko: Re: Site query to DB?
Kirjoitti: ziycon - tammikuu 11, 2006, 12:34:12 IP
i've done that, when i open the page i get thie error below, the website is in a folder called html and smf is in a folder called forum, these to folders are in the same directory as eachother.

Warning: main(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/index1.php on line 118

Warning: main(http://forum/SSI.php?ssi_whosOnline()): failed to open stream: Address family not supported by protocol in /var/www/html/index1.php on line 118

Warning: main(): Failed opening 'http://forum/SSI.php?ssi_whosOnline()' for inclusion (include_path='.:/php/includes:/usr/share/php') in /var/www/html/index1.php on line 118

Any ideas?
Otsikko: Re: Site query to DB?
Kirjoitti: ziycon - tammikuu 11, 2006, 12:46:58 IP
I fixed the first errors there but now i have these two errors, any idea hw i get around them? i need to access the SSI.php file from

\var\www\forum\

but the the website is kept in

\var\www\html\

Here are the errors:

Warning: main(/SSI.php?ssi_whosOnline()): failed to open stream: No such file or directory in /var/www/html/index1.php on line 118

Warning: main(): Failed opening '/SSI.php?ssi_whosOnline()' for inclusion (include_path='.:/php/includes:/usr/share/php') in /var/www/html/index1.php on line 118
Otsikko: Re: Site query to DB?
Kirjoitti: Leipe Po - tammikuu 11, 2006, 01:18:29 IP
that means your path is wrong, try
<?php require("./forum/SSI.php"); ?>
or
<?php require("../forum/SSI.php"); ?>
Otsikko: Re: Site query to DB?
Kirjoitti: ziycon - tammikuu 11, 2006, 01:23:33 IP
no, it didnt work, that would only bring me back to

\var\www
Otsikko: Re: Site query to DB?
Kirjoitti: Leipe Po - tammikuu 11, 2006, 01:30:59 IP
hmmz interesting.....
the ../ part should bring you back to WWW and then the forum/ part should send you to the ssi file so i'm riddled,
could you do a test for me?

create a file(any name) in you WWW folder and use:

<?php require("forum/SSI.php"); ?>

<?php ssi_logOnline(); ?>


also try playing with the url like:
<?php require("/forum/SSI.php"); ?>
<?php require("/../forum/SSI.php"); ?>
<?php require("/./forum/SSI.php"); ?>
Otsikko: Re: Site query to DB?
Kirjoitti: ziycon - tammikuu 11, 2006, 01:38:33 IP
i fixed that and got it working. Thank you for all your help.

One last question, how do i put this line into the site:

?ssi_whosOnline()
Otsikko: Re: Site query to DB?
Kirjoitti: Leipe Po - tammikuu 11, 2006, 01:41:13 IP
<?php ssi_whosOnline(); ?>
this should work fine, ssi has it all tuckt away in function so
Otsikko: Re: Site query to DB?
Kirjoitti: newy - kesäkuu 06, 2007, 05:59:06 AP
I know this is an old post but its all i could find about it using the searc..

Im getting this same error:  Im trying to call the functions into my site to display the recent posts on my homepage..  The forum is on a sub.domain so i make the call:

<?php require("http://forum.mysite.com/SSI.php"); ?>
&/or
<?php include("http://forum.mysite.com/SSI.php"); ?>


& using : <?php ssi_recentPosts(); ?>

But get this error:

Please don't access SSI.php by URL directly; you may want to use the path ('SSI.php') or add ?ssi_function=something

basically saying not to use direct paths.. How else am i supposed to call it from a sub.domain if not using direct paths ?


Can anyone help with this as its getting rather frustrating :(

regards

newy
Otsikko: Re: Site query to DB?
Kirjoitti: Daniel15 - kesäkuu 06, 2007, 08:20:29 AP
LainaaBut get this error:

Please don't access SSI.php by URL directly; you may want to use the path ('SSI.php') or add ?ssi_function=something

basically saying not to use direct paths.. How else am i supposed to call it from a sub.domain if not using direct paths ?
Just like the error says, use ssi_function=something. Using http://forum.mysite.com/SSI.php?ssi_function=recentPosts should work.

Note that even though it's on a subdomain, you should still be able to access SSI.php via its file path (as long as the site is on the same server). Something like:

require('/home/username/public_html/forum/SSI.php');

Should work, and this gives you more flexibility (including SSI functions via URL doesn't allow you to customise how the output is formatted, whereas with the PHP ones, you can get the raw data and output it yourself :))
Otsikko: Re: Site query to DB?
Kirjoitti: newy - kesäkuu 08, 2007, 05:07:55 AP

Hi daniel..  Thanks for your reply !.. i only just got too it today..  I managed to output the data.. but how do i customise it ?

I pressumed i could just "Style" a Div but that doesnt take effect ... Where and how can i Style the Output it gives me ? .. It looks pretty horrible at the moment ..

Is there a way of getting rid of the dates on it aswell ?

reghards

newy
Otsikko: Re: Site query to DB?
Kirjoitti: Daniel15 - kesäkuu 08, 2007, 05:33:01 AP
To change how the data is output, you'd need to access SSI.php directly, by its file path.

At the top of the page, put this:

<?php
require('forum/SSI.php');
?>



Where you'd like the data to appear, put this:

<?php
// Get the recent posts
$posts ssi_recentPosts(8null'array'); // 8 = number of posts to display

// Loop through all of them
echo '
<table border="0" class="ssi_table">'
;
foreach (
$posts as $post)
echo '
<tr>
<td align="right" valign="top" nowrap="nowrap">
['
$post['board']['link'], ']
</td>
<td valign="top">
<a href="'
$post['href'], '">'$post['subject'], '</a>
'
$txt[525], ' '$post['poster']['link'], '
'
$post['new'] ? '' '<a href="' $scripturl '?topic=' $post['topic'] . '.msg' $post['new_from'] . ';topicseen#new"><img src="' $settings['images_url'] . '/' $context['user']['language'] . '/new.gif" alt="' $txt[302] . '" border="0" /></a>''
</td>
<td align="right" nowrap="nowrap">
'
$post['time'], '
</td>
</tr>'
;
echo 
'
</table>'
;
?>



The "array" ssi_recentPosts output method returns all the data in a raw form, and then we output it via our code. This allows you to customise how it's displayed. Note that my code is the exact same code used by default. You may customise this as much as you want (eg. if you don't want to use a table, and instead just want to display a list).

To get rid of the date, remove this bit from the code:

<td align="right" nowrap="nowrap">
', $post['time'], '
</td>
Otsikko: Re: Site query to DB?
Kirjoitti: newy - kesäkuu 08, 2007, 10:32:59 AP
Ok i have no idea what is going on!  If i use the following code below:


<?php
require('forum/SSI.php');
?>



and alter the path forum/SSI.php  to my own file path  http://forum.mysite.blah/SSI.php  I get an error telling me to use the ssi_function=somthing

If i use the ssi_function=somthing  it displays the recent posts albeit at the top of my page (obviously)... But if i use that same ss-_function in the centre of my page where i want the output displayed, i have no control over customisation..

The code below  when used gives me error: Fatal error: Call to undefined function: ssi_recentposts()
SO no matter what combination or whatever i use all this. non of it is working..



<?php
// Get the recent posts
$posts ssi_recentPosts(8null'array'); // 8 = number of posts to display

// Loop through all of them
echo '
<table border="0" class="ssi_table">'
;
foreach (
$posts as $post)
echo '
<tr>
<td align="right" valign="top" nowrap="nowrap">
['
$post['board']['link'], ']
</td>
<td valign="top">
<a href="'
$post['href'], '">'$post['subject'], '</a>
'
$txt[525], ' '$post['poster']['link'], '
'
$post['new'] ? '' '<a href="' $scripturl '?topic=' $post['topic'] . '.msg' $post['new_from'] . ';topicseen#new"><img src="' $settings['images_url'] . '/' $context['user']['language'] . '/new.gif" alt="' $txt[302] . '" border="0" /></a>''
</td>
<td align="right" nowrap="nowrap">
'
$post['time'], '
</td>
</tr>'
;
echo 
'
</table>'
;
?>




<td align="right" nowrap="nowrap">
', $post['time'], '
</td>


Edited by Daniel15: Fixed formatting
Otsikko: Re: Site query to DB?
Kirjoitti: Daniel15 - kesäkuu 08, 2007, 11:33:12 AP
Do not use the URL for the SSI.php file, use the path to the file ;).
Go to your forum's admin panel, and click on the "Server Settings" link. Your forum's directory will be listed under "SMF Directory". Change the require(...) line to include this path with SSI.php appended to it.
Otsikko: Re: Site query to DB?
Kirjoitti: newy - kesäkuu 08, 2007, 07:17:37 IP

Many thanks Daniel !...

Very much appreciated  :)  -  Its a good job somebody knows what their doing :D
Otsikko: Re: Site query to DB?
Kirjoitti: Daniel15 - kesäkuu 08, 2007, 08:24:50 IP
No problem ;)
If you have any further questions, please feel free to ask :)
Otsikko: Re: Site query to DB?
Kirjoitti: newy - kesäkuu 09, 2007, 08:27:45 AP
HI daniel there is one thing

Ive integrated SMF with coppermine etc..  but how do i get coppermine gallery or slideshow or images to show up on my forum and and pages of my site..

Is there a list of php includes i can use ? like SSI.php function ? Ive had a look but and search but cant find anything on it.