Jump to content

I need help understanding Multidimensional Arrays in Smarty with Mysql


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.

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.