PHP Arrays and Smarty
Posted: Sun Feb 21, 2010 2:44 pm
Hello Everyone. I have this Issue. I am using Smarty with Arrays. I cannot get this array to form correctly from a database. the category_name array is not forming correctly. It lays it our on the HTML side as 1=>"Category Name". How can i make a key and a value from a MySQL Database and have Smarty Place it down correctly,
Here is my Smarty Code:
Thanks Guys
Code: Select all
<?php
$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
$db->connect();
$sql = "SELECT * FROM store_info";
$record = $db->query_first($sql);
$store_name = $record['store_name'];
$sql_cat = "SELECT * FROM store_categories WHERE category_show_top_menu='Y'";
$rows = $db->fetch_all_array($sql_cat);
foreach($rows as $record){
$category_name[] = "$record[category_id] => $record[category_name]";
}
$db->close();
?>
Code: Select all
<li><a href="?i=home" >Home</a></li>
{foreach from=$category_name key=k item=v}
<li><a href="?i=product&x={$k}">{$v}</a></li>
{/foreach}
</ul>