...

View Full Version : One Result while looping



ajloun
02-16-2010, 07:29 AM
Hello

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


<?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']);
}
?>

tmplate



<table cellpadding="5" cellspacing="5" class="outer">
<tr>
<td class="even">
<{$name}></td>
</tr>


<tr>
<td class="even">
<{$title}></td>
</tr>

</table>

Dormilich
02-16-2010, 08: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.

PappaJohn
02-16-2010, 01: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.

ajloun
02-16-2010, 07:03 PM
@PappaJohn thx

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

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

ajloun
02-16-2010, 08:42 PM
@PappaJohn

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum