keldorn Posted September 21, 2009 Share Posted September 21, 2009 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. 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 Quote Link to comment https://forums.phpfreaks.com/topic/175052-i-need-help-understanding-multidimensional-arrays-in-smarty-with-mysql/ Share on other sites More sharing options...
keldorn Posted September 21, 2009 Author Share Posted September 21, 2009 OK, I tried this. {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. Quote Link to comment https://forums.phpfreaks.com/topic/175052-i-need-help-understanding-multidimensional-arrays-in-smarty-with-mysql/#findComment-922613 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.