Author Topic: Foreach & site_template  (Read 5794 times)

0 Members and 1 Guest are viewing this topic.

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Foreach & site_template
« on: September 05, 2007, 12:56:07 PM »
I'm trying to show RSS feed to user profile, but my mod doesn't work.

Can anyone tell me what i'm doing wrong, becouse it shows only last entry/feed:

Code: [Select]
require_once 'magpierss/rss_fetch.inc';

$url = 'http://www.slo-foto.net/backend20.php';
$num_items = 5;
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, $num_items);
foreach ( $items as $item ) {
$title = $item[title];
$url   = $item[link];
$rssoutput = "<a href=$url>$title</a><br>";
}

    $site_template->register_vars(array(
    "rsstitle" => $user_rss_title,
    "rsslink" => $user_rss_link,
    "rssoutput" => $rssoutput,
    ));

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Foreach & site_template
« Reply #1 on: September 05, 2007, 01:43:14 PM »
Try:

Code: [Select]
$url = parse_url('http://www.slo-foto.net/backend20.php');
$num_items = 5;
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, $num_items);
foreach ($items as $item) {
$title = $item['title'];
$url   = $item['link'];
$rssoutput = "<a href=\''.$url.'\'>' . $title . '</a><br />";

    $site_template->register_vars(array(
    "rsstitle" => (isset($user_rss_title)) ? format_text(stripslashes($user_rss_title), 2) : "",
    "rsslink" => (isset($user_rss_link)) ? trim($user_rss_link) : "", // Where user rss link ?
    "rssoutput" => (isset($rssoutput)) ? trim($rssoutput) : ""
    ));
}

+ where $user_rss_link ? ;)
« Last Edit: September 05, 2007, 01:59:20 PM by thunderstrike »
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Foreach & site_template
« Reply #2 on: September 05, 2007, 01:54:02 PM »
Actualy this is the whole code, but it still don't work:

Code: [Select]
require_once 'magpierss/rss_fetch.inc';

$sql_rss = "SELECT user_rss_link, user_rss_title
FROM ".USERS_TABLE."
WHERE user_id = ".$user_row['user_id']."";
$result_rss = $site_db->query($sql_rss);
$row_rss = $site_db->fetch_array($result_rss);
$user_rss_link = $row_rss['user_rss_link'];
$user_rss_title = $row_rss['user_rss_title'];
$num_items = 5;
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, $num_items);

foreach ($items as $item) {
$title = $item['title'];
$url   = $item['link'];
$rssoutput = "<a href=\'$user_rss_link\'>' . $title . '</a><br />";

    $site_template->register_vars(array(
    "rsstitle" => (isset($user_rss_title)) ? format_text(stripslashes($user_rss_title), 2) : "",
    "rsslink" => (isset($user_rss_link)) ? trim($user_rss_link) : "", // Where is user rss link ?
    "rssoutput" => (isset($rssoutput)) ? trim($rssoutput) : ""
    ));
}

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Foreach & site_template
« Reply #3 on: September 05, 2007, 01:56:48 PM »
Set $row_css in while loop. After $items close while. ;)

+

Code: [Select]
$rssoutput = "<a href=\'$user_rss_link\'>' . $title . '</a><br />";

for:

Code: [Select]
$rssoutput = "<a href=\''.$user_rss_link.'\'>' . $title . '</a><br />";

I edit post before ...
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Foreach & site_template
« Reply #4 on: September 05, 2007, 02:08:33 PM »
I'm realy grateful that you're helping me,
but I'm little confused how to do while loop with $row_css after $items while close?  :oops:

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Foreach & site_template
« Reply #5 on: September 05, 2007, 02:17:41 PM »
Ok so like this:

Code: [Select]
$num_items = 5;
while ($row_rss = $site_db->fetch_array($result_rss)) {
$user_rss_link = $row_rss['user_rss_link'];
$user_rss_title = $row_rss['user_rss_title'];
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, $num_items);
}

No see $url source (for fetch_rss($url)) ...
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Foreach & site_template
« Reply #6 on: September 05, 2007, 02:24:47 PM »
I don't think that is the problem, becouse if I use my first code and add echo inside foreach, I see all resoults. That's why I think there is problem with
Code: [Select]
$site_template->register_vars(array(..
Code: [Select]
require_once 'magpierss/rss_fetch.inc';

$url = 'http://www.slo-foto.net/backend20.php';
$num_items = 5;
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, $num_items);
foreach ( $items as $item ) {
$title = $item[title];
$url   = $item[link];
$rssoutput = "<a href=$url>$title</a><br>";
        echo $rssoutput;
}

    $site_template->register_vars(array(
    "rsstitle" => $user_rss_title,
    "rsslink" => $user_rss_link,
    "rssoutput" => $rssoutput,
    ));

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Foreach & site_template
« Reply #7 on: September 05, 2007, 02:31:14 PM »
Quote
I don't think that is the problem, becouse if I use my first code and add echo inside foreach, I see all resoults. That's why I think there is problem

Correct. Sorry, is:

Code: [Select]
$num_items = 5;
while ($row_rss = $site_db->fetch_array($result_rss)) {
$user_rss_link = $row_rss['user_rss_link'];
$user_rss_title = $row_rss['user_rss_title'];
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, $num_items);
}
$rssoutput = "";
foreach ($items as $item) {
$title = $item['title'];
$url   = $item['link'];
$rssoutput .= "<a href=\''.$user_rss_link.'\'>' . $title . '</a><br />";   
}
$site_template->register_vars(array(
    "rsstitle" => (isset($user_rss_title)) ? format_text(stripslashes($user_rss_title), 2) : "",
    "rsslink" => (isset($user_rss_link)) ? trim($user_rss_link) : "",
    "rssoutput" => (isset($rssoutput)) ? trim($rssoutput) : ""
));
unset ($rssoutput);
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Foreach & site_template
« Reply #8 on: September 05, 2007, 02:44:00 PM »
Correct!

Thank you very much!!!  :D