Jump to content

[SOLVED] Help With Smarty Code


steviez

Recommended Posts

Hi,

 

I am using smarty to design my site and need to convert this code so i can use it in a smarty template:

 

$result = mysql_query("SELECT * FROM uploads where uploader = 'steviez'");
while($row = mysql_fetch_array($result)){
echo '<tr class="sub_table highlight">';
echo '<td></td>';
echo '<td>'.$row['name'].'</td>';
echo '<td>1 (MB)</td>';
echo '<td><a href="#" target="_blank">Click here</a></td>';
echo '<td><a href="#">Click Here</a></td>';
echo '<td><a href="#">Remove</a> <a href="#">Add</a></td>';
echo '</tr>';
}
}

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/83458-solved-help-with-smarty-code/
Share on other sites

PHP code:

<?php
// ...

$result = mysql_query("SELECT * FROM uploads where uploader = 'steviez'");

$uploads = array();
while($row = mysql_fetch_array($result))
{
$uploads[] = $row;
}

// we'll assume that the smarty object is called $smarty
$smarty->assign('uploads', $uploads);

// ...
?>

 

Smarty template code:

{section name=upload loop=$uploads}
<tr class="sub_table highlight">
	<td></td>
	<td>{$uploads[upload].name}</td>
	<td>1 (MB)</td>
	<td><a href="#" target="_blank">Click here</a></td>
	<td><a href="#">Click Here</a></td>
	<td><a href="#">Remove</a> <a href="#">Add</a></td>
</tr>
{/section}

 

 

Look, I have never touched Smarty before, yet I was able to create this in no time. Reading the Smarty manual might be a good idea.

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.