Jump to content

I need help understanding Multidimensional Arrays in Smarty with Mysql


keldorn

Recommended Posts

This is the frist time I've had to deal with this, I belive its called multidimensional arrays? I have 2 arrays after pulling them from Mysql (This have been chopped down to remove unneeded information/logic.)

 

$Category =

Array ( [0] => Array ( [id] => 1 [category_name] => php [slug] => PHP ) [1] => Array ( [id] => 2 [category_name] => javascript [slug] => Javascript ) ) 

 

 

$article =

Array ( [id] => 1 [article_content] => Welcome this is your first article, use the admin panel to edit or delete this. [article_category] => 1 [article_author] => Keldorn ) ) 

 

 

I need to take the [article_category]  from $article and match it too [id] of $category and the get the corresponding [category_name]

 

Like if the article_category => 1  then the it should print  "PHP" from the category array. :confused:

 

If someone could show me how to do this with Smarty snytax that would be great!

This is what I have so far.

 

{section name=post loop=$article}			
<span class="meta">Published by: {$article[post].article_author} in Category (ie. PHP)<!-- need a multidimensional array here --></div>			
{sectionelse}
Nothing Found!
{/section}

 

Keldorn  :psychic:

OK, I tried this.  :D

{section name=post loop=$article}         
<span class="meta">Published by: {$article[post].article_author} in Category {$category[post].category_name}
</div>         
{sectionelse}
Nothing Found!
{/section}

 

It puts on the the page

Published by: Keldorn in Category PHP

 

buts its still wrong becuase the article_Category for that one was 2 not 1, so it should say Javascript. This is becuase its using the Incrementing ID of the array to match the category_name , not the article_catogory field (!)

 

I tried this.

{$category[article_category].category_name}

 

But get Undefinded index: article_category.

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.