View Full Version : One Result while looping

02-16-2010, 08:29 AM

In this code , it Should Print out all the titles where cid=$cid..

But for Some reason it only Prints One Result ( One title) . when i'm sure i have More than One Title in my Mysql ..

The Funy thing is it all ok if i do Not use Smarty ..

this the php

$cid = $_GET['cid'];
$data = mysql_query("SELECT * FROM ".$DB->prefix("gallery")." WHERE category='$cid' ") or die(mysql_error());

while($info = mysql_fetch_array( $data ))
$mytest= array();

$mytest['title'] = $myts->htmlSpecialChars($info['title']);
$mytest['name'] = $myts->htmlSpecialChars($info['name']);

$smarty->assign('title', $mytest['title']);
$smarty->assign('name', $mytest['name']);


<table cellpadding="5" cellspacing="5" class="outer">
<td class="even">

<td class="even">


02-16-2010, 09:58 AM
judging from the template (ok, never have used smarty), you can’t have more than one output, plus, in the smarty assignment, it looks like you overwrite the previous value in every cycle.

02-16-2010, 02:02 PM
Dormilich is correct.

1. Your php file will have to create an array containing your titles and names (and any other info you want to display) and then assign that array to a smarty variable.

2. In your template file, you need to use a {foreach} loop to display the data in the array.

02-16-2010, 08:03 PM
@PappaJohn thx

i edited my php to use arry .But i'm new with Smarty .. How to loop?

02-16-2010, 08:06 PM
Syntax & examples (http://www.smarty.net/manual/en/language.function.foreach.php)

02-16-2010, 09:42 PM

Thank you Man .. Got it Right this Time A+

02-16-2010, 10:33 PM
you're welcome, glad you got it.