CaptainChainsaw Posted August 20, 2008 Share Posted August 20, 2008 Hi all, I think I have an associative array problem. I need to return data from the DB and loop over it using my smarty template. It appears to show '1' which is the ID in the db and the first character in each of the other two db fields which seems quite bizarre to me. Anyone got any ideas on this? Thanks again! CC public function retrieveFaq(){ $result=mysql_query("SELECT id, question, answer FROM faq ORDER BY id DESC", $this->_db->connect()); //$row = mysql_fetch_assoc($result); $row =mysql_fetch_array($result, MYSQL_ASSOC); return $row; } $faq=new faq('','',$db); $results = $faq->retrieveFaq(); $smarty->assign('results', $results); $smarty->display('editfaq.tpl'); {foreach key=cid item=con from=$results} Question: {$con.cid} <br /><br /><br /> Answer: {$con.answer} <form action="" method="post"> <input type="hidden" name="id" value="{$cid}" /> <input type="submit" name="submit" value="Edit FAQ" /> </form> <!-- <a href="contact.php?contact_id={$cid}">{$con.name} - {$con.nick}</a><br /> --> {foreachelse} No items were found in the search {/foreach} The output I get is: Question: 1 Answer: 1 [EDIT FAQ] Question: d Answer: d [EDIT FAQ] Question: w Answer: w [EDIT FAQ] Link to comment https://forums.phpfreaks.com/topic/120554-solved-associative-array-php5mysqlsmarty-problem/ Share on other sites More sharing options...
CaptainChainsaw Posted August 20, 2008 Author Share Posted August 20, 2008 adding this in to the retrieveFaq() method sorted it: $rows = array(); while ($row = mysql_fetch_assoc($result)) $rows[] = $row; return $rows; Link to comment https://forums.phpfreaks.com/topic/120554-solved-associative-array-php5mysqlsmarty-problem/#findComment-621339 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.