Jump to content

[SOLVED] associative array (php5/mysql/smarty problem)


CaptainChainsaw

Recommended Posts

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]

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.