Reply to display array data in a smarty tpl file

Your name:

Reply:


Posted by bkeep on 03/20/06 11:40

i am having an issue with displaying the array that gets inserted into
the data base some background on what i have.

I start off with a regular form and pass the info as an array over to
the php and insert it into the database as a string with the following
[code]
<form action="events.php" method="post" name="events" id="events">

<select name="invitation[]" size="4" multiple="multiple">
<option value="I1">Amature</option>
<option value="I2">Club Tournament</option>
<option value="I3">Must Qualify</option>
<option value="I4">Public / Open</option>
<option value="I5">Professional</option>
<option value="I6">Membership Required</option>
</select>

<input name="submit" type="submit" value="Submit" />
</form>
[/code]

there is of course more to the form than that but i left it out for
clarity and the sql stuff is
[code]
$tplEvents = new TplLoad();

if (getParam("submit","")) {

$invitation = serialize($_POST["invitation"]);

$sql = "INSERT INTO events (invitation) VALUES ( '" . $invitation
.. "')";
$res = query($sql);
{
[/code]

and that inserts this a:3:{i:0;s:2:"I1";i:1;s:2:"I2";i:2;s:2:"I3";} into
the database all is good so far and here is where i have trouble.

i pull the data out using

[code]
$sql = "SELECT * FROM events";
$res = query($sql);
$c=0;
while ($a_row = mysql_fetch_array($res)) {

$invitation[$c]["invitation"] = unserialize($a_row["invitation"]);
$c++;
}
$tplEvents->assign('invitation',$invitation);
$tplEvents->display("events.tpl");
[/code]
and the tpl looks like this
[code]
<p>
{foreach item=item from=$invitation}
{$item.invitation}
{/foreach} </p>
[/code]
this will actually display array array and if i do not use the
unserialize function i get the
a:3:{i:0;s:2:"I1";i:1;s:2:"I2";i:2;s:2:"I3";} and a:1:{i:0;s:2:"I3";}
the code below will display the correct output in the template such as
I1 I2 I3 , but it will not loop through the results it only will show
the last entry added in the database
[code]
$invitation = unserialize($a_row["invitation"]);
[/code]
I am not sure what i need to do here im lost thanks for any help
Regards,
Brandon

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация