TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,020
  • Total Topics: 21,332
  • Online today: 926
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 645
  • Total: 645

Need a little coding help

Started by zarprime, April 13, 2010, 03:10:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ZarPrime

Using SMF 2.0 RC3 / TP 1.0 beta 5-1

The following code in an article ...

echo '<span class="smalltext">Last 5 Posts from Board #1</span>';
echo '<hr>';
$result=ssi_boardNews(1,5,0,100, 'echo');
echo '<ul style="margin-left: 2px;">';
foreach($result as $my){
echo '<li>'.$my['link'].'</li>';
}
echo '</ul>';


... is causing the following error consistently ...

http://talesofthehavenexpanse.com/smf2test/index.php?page=14
2: Invalid argument supplied for foreach()
File: /home/talesoft/public_html/smf2test/Themes/default/TPShout.template.php (main sub template - eval?)
Line: 5


Can anyone see what I'm doing wrong in that code?  Do I have an extra quote in there or something?  BTW, the article is rendered just the way I would expect it to be.

ZarPrime

Freddy

Try changing :

$result=ssi_boardNews(1,5,0,100, 'echo');

to :

$result=ssi_boardNews(1,5,0,100, 'array');

ZarPrime

Thanks freddy, I'll let you know.  Ichbin is playing around on my test site right now trying to get the Avatars to show in FP posts right now.  I'll change that once he's finished.  Why would I use "array" instead of "echo"?  Or, what is the difference between the two?

ZP

Freddy

#3
Well a function like that can do a couple of things with it's output:

1 ) It can automatically echo out the data and HTML itself, so you get instant results on the page.  To do that you just do : ssi_boardNews(1,5,0,100, 'echo');

2) If you just want the data then you can pull it into an array so you can further play around with it, before echoing it out to the page.  To do that you use : $result=ssi_boardNews(1,5,0,100, 'array');

In your original code by using 'echo' you were trying to assign the output into an array but the function was trying to echo it out as HTML.  But that's incompatible, which is what was causing the error - because the foreach part was expecting an array.

But if you use the word 'array' in there it loads it into the array you specified, so in your case all the results would go into the array called $result.  Then once it is in the $results array you can do what you want with the data and echo out just the parts you need and in whatever layout you see fit.

I hope that made sense. :o

BTW, if you are happy with the way it was being output then you could just remove the foreach loop entirely and just use this :

ssi_boardNews(1,5,0,100, 'echo');

I suggest you try a blank article and use that one line, then you can see what SSI does by itself.

ZarPrime

Yep, makes perfect sense.  Thanks Bro'. O0

ZP

ZarPrime

Using this code ...

echo '<span class="smalltext">Last 5 Posts from Board #1</span>';
echo '<hr>';
$result=ssi_boardNews(1,5,0,100, 'array');
echo '<ul style="margin-left: 2px;">';
foreach($result as $my){
echo '<li>'.$my['link'].'</li>';
}
echo '</ul>';


fixes the error but is not the look I want (see attached image).

Using ...

echo '<span class="smalltext">Last 5 Posts from Board #1</span>';
echo '<hr>';
$result=ssi_boardNews(1,5,0,100, 'echo');


gives the same look as the first code, but without the error ...
http://talesofthehavenexpanse.com/smf2test/index.php?page=13

Thanks Freddy,
ZarPrime

IchBin

You're code worked fine for me without error. Are you sure you have a board with that ID that is accessible?

ZarPrime

Yep, sure do.  It works fine for me as well like this ...

echo '<span class="smalltext">Last 5 Posts from Board #1</span>';
echo '<hr>';
$result=ssi_boardNews(1,5,0,100, 'echo');


and without the foreach error I got earlier.

Here's the link --> http://talesofthehavenexpanse.com/smf2test/index.php?page=13

ZP

Freddy


This website is proudly hosted on Crocweb Cloud Website Hosting.