Re: [SMARTY] assign() Problem - Urgent

From: Date: Mon, 14 Jul 2003 07:38:56 +0000
Subject: Re: [SMARTY] assign() Problem - Urgent
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9886@lists.php.net to get a copy of this message
--- Balaji Nallathambi <balaji_smarty@yahoo.com> wrote: > Hi all > > My Code looks like below > > this is index.php > > $arrayptr; > $recordPtr; what was the purpose of that? > // $result="select * from projectdetails" > while($mydata=mysql_fetch_row($result)) > { > $arraptr=0; > $smarty->assign("ProjectID",array($arrayptr,$mydata[0])); > $arraptr = $arraptr+1; > } main problem is that you set $arraptr=0; each time you loop so you end up overwriting the previous value also, it's good practice to specify what fields to select and use less confusing names for your vars try this: $ProjectID = array(); $result='select project_id, field1, field2 from projectdetails'; $i=0; while($mydata=mysql_fetch_array($result)) { $ProjectID[$i] = $mydata['project_id']; $i++; } // or don't worry about the $i counter and do this while($mydata=mysql_fetch_array($result)) { $ProjectID[] = $mydata['project_id']; } $smarty->assign("ProjectID",$ProjectID); > The value in the Database for Projer ID are > P100 > P200 > P300 > > in the Template file iam using like below > > index.tpl > > {section name=Project loop=$ProjectID} > > id: {$ProjectID[Project]}<br> > > {/section} > > Iam getting only the last value stores that is > > id :P300 is printed > > I don't how to get the values from the other's ls > help me to solve the problem. > __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com

« previous php.smarty.general (#9886) next »