Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

[solved]smarty->append
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sat Nov 13, 2004 11:13 pm    Post subject: [solved]smarty->append Reply with quote

I am pulling links from my database, and I am trying to append them to the smarty value to be outputted in the template with a {section}.

Here is the function:
[php:1:5ce802da64]
<?php
function outputNavs()
{
global $db, $template, $config;
$template->assign('links','');
$sql = "SELECT * FROM ". HEADER_NAV_TABLE ." ORDER BY nav_id";

if(!$result = $db->query($sql))
{
message_die(GENERAL_ERROR,"Couldn't SQL the header navigation links from the database in " .__FILE__.' on line '.__LINE__.' <br />'.$sql.'<br />'.mysql_error());
}
else
{
//pick up here
while( $row = $db->fetch_row($result))
{
$template->append('links',array('title' => $row['nav_name'], 'url' => $row['nav_link']));
}

}


}
?>[/php:1:5ce802da64]

and in my template I have:
Code:

{section name=cycle loop=$links}
{strip}
<a href="{$links[cycle].url}">{$links[cycle].title}</a>
{/strip}
{/section}
{$ACP}

NOTE: $ACP is a link to my admin control panel.

Why is this not displaying, it should make a cell via CSS.
But the data is not being iterated through to be shown. What am I doing wrong?
_________________
My site | My CMS Development site


Last edited by crxgames on Mon Nov 15, 2004 12:44 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Nov 14, 2004 12:31 am    Post subject: Reply with quote

Try this instead:

[php:1:d5a1dee1b7]<?php
function outputNavs()
{
global $db, $template, $config;
$sql = "SELECT * FROM ". HEADER_NAV_TABLE ." ORDER BY nav_id";

$links = array();
if(!$result = $db->query($sql))
{
message_die(GENERAL_ERROR,"Couldn't SQL the header navigation links from the database in " .__FILE__.' on line '.__LINE__.' <br />'.$sql.'<br />'.mysql_error());
}
else
{
//pick up here
while( $row = $db->fetch_row($result))
{
$links[] = array('title' => $row['nav_name'], 'url' => $row['nav_link']);
}

}

$template->assign('links', $links);
}

?>[/php:1:d5a1dee1b7]
Building arrays using append() in a loop is less efficient than building the entire array and then passing it via a single assign.
Back to top
View user's profile Send private message
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sun Nov 14, 2004 12:43 am    Post subject: Reply with quote

Still didn't output them. Sad
_________________
My site | My CMS Development site
Back to top
View user's profile Send private message Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Nov 14, 2004 1:18 am    Post subject: Reply with quote

Put a {debug} into your template. It seems like the $links isn't being populated.
Back to top
View user's profile Send private message
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sun Nov 14, 2004 1:22 am    Post subject: Reply with quote

It is being populated...

only thing I can guess is that I am not going through the data correctly in the template.
_________________
My site | My CMS Development site
Back to top
View user's profile Send private message Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Nov 14, 2004 3:01 am    Post subject: Reply with quote

Quote:
It is being populated...

Okay--and you verified it is populated correctly, I imagine. Your template looks okay to me so a big hmmm. What is the loop actually producing--nothing at all? Ensure that error reporting is pumped up and turn template debugging on -- I wonder if you are getting notices or other errors.
Back to top
View user's profile Send private message
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sun Nov 14, 2004 3:07 am    Post subject: Reply with quote

It was getting the data to the debug. I'll set the debug on smarty on.
_________________
My site | My CMS Development site
Back to top
View user's profile Send private message Visit poster's website AIM Address
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sun Nov 14, 2004 3:09 am    Post subject: Reply with quote

http://216.68.134.98/portal2.0/portal.php?SMARTY_DEBUG whenever my computer is on. It has the values too.
_________________
My site | My CMS Development site
Back to top
View user's profile Send private message Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Nov 14, 2004 3:32 am    Post subject: Reply with quote

According to the debug window, there isn't a variable called $links. There does seem to be one that fits the bill that is called $nav_links. Could that be it?
Back to top
View user's profile Send private message
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sun Nov 14, 2004 3:57 am    Post subject: Reply with quote

No, I made it assign to the name nav_links
_________________
My site | My CMS Development site
Back to top
View user's profile Send private message Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Nov 14, 2004 4:17 am    Post subject: Reply with quote

...and you made your template read from $nav_links? Please, keep your sample code that you post here as close to the real thing as possible.

Anyhow, I'm getting the feeling that I will have to ask you for each piece of information required to solve this little puzzle. As I have no interest in doing that, I suggest you consider providing more details as I can't see what is wrong based on what you posted so far.

Good luck!
Back to top
View user's profile Send private message
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sun Nov 14, 2004 4:21 am    Post subject: Reply with quote

Problem is the array made in the outputNavs function is not being iterated through and displayed, but has data.

Current function:
[php:1:eea11795f6]<?php
//////////////////////////////////////
//Function: outputNavs()
//Ouputs the header navigation links
//////////////////////////////////////
function outputNavs()
{
global $db, $template, $config;
$sql = "SELECT * FROM ". HEADER_NAV_TABLE ." ORDER BY nav_id";

$links = array();
if(!$result = $db->query($sql))
{
message_die(GENERAL_ERROR,"Couldn't SQL the header navigation links from the database in " .__FILE__.' on line '.__LINE__.' <br />'.$sql.'<br />'.mysql_error());
}
else
{
//pick up here
while( $row = $db->fetch_row($result))
{
$links[] = array('title' => $row['nav_name'], 'url' => $row['nav_link']);

}

}

$template->assign('nav_links', $links);
}
?>[/php:1:eea11795f6]

and current tpl:
Code:

{section name=cycle loop=$nav_links}
{strip}
<a href="{$nav_links[cycle].url}">{$nav_links[cycle].title}</a>
{/strip}
{/section}
{$ACP}

_________________
My site | My CMS Development site
Back to top
View user's profile Send private message Visit poster's website AIM Address
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sun Nov 14, 2004 4:13 pm    Post subject: Reply with quote

Here is the table structure if that helps.
Code:

CREATE TABLE `portal_navs` (
  `nav_id` int(8) NOT NULL auto_increment,
  `nav_name` varchar(128) default NULL,
  `nav_link` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`nav_id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

#
# Dumping data for table `portal_navs`
#

INSERT INTO `portal_navs` (`nav_id`, `nav_name`, `nav_link`) VALUES (1, 'Test link to acp', '/admin/index.php');


Should I be using the foreach?
_________________
My site | My CMS Development site
Back to top
View user's profile Send private message Visit poster's website AIM Address
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sun Nov 14, 2004 7:01 pm    Post subject: Reply with quote

I have tried the following foreach to just get it to output with no success.
Code:

{foreach name=outer item=contact from=$contacts}
  {foreach key=key item=item from=$contact}
    {$key}: {$item}<br>
  {/foreach}
{/foreach}

_________________
My site | My CMS Development site
Back to top
View user's profile Send private message Visit poster's website AIM Address
crxgames
Smarty Rookie


Joined: 13 Nov 2004
Posts: 16

PostPosted: Sun Nov 14, 2004 8:50 pm    Post subject: Reply with quote

Someone has to know, I need to have this working by the end of the day.
_________________
My site | My CMS Development site
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP