Jump to content

[SOLVED] [php/smarty] problem with displaying db data using Smarty's {section} function


michalchojno

Recommended Posts

I seem to have a problem to display db data using Smarty's {section} function.

 

Here is what I have:

table1:

id

1

3

4

14

15

 

index.php

require('Smarty.class.php');

 

$smarty = new Smarty;

 

$smarty->template_dir = 'c:...'; //use the correct path

$smarty->config_dir = 'c:...'; //use the correct path

$smarty->cache_dir = 'c:...'; //use the correct path

$smarty->compile_dir = 'c:...'; //use the correct path

 

$link = mysql_connect ('host', 'user', 'pass'); // use the right input data

$db = mysql_select_db('db', $link); // use the right input data

 

$q = "Select * from table1 order by id";

$r = mysql_query ($q, $link);

 

while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {

$arrid[($row['id'])] = $row['id'];

}

 

$smarty -> assign (

array(

'Itemid' => $arrid

)

);

 

$smarty->display('index.tpl');

 

mysql_free_result ($r);

mysql_close ($link);

 

index.tpl

......

{section name=listt loop=$Itemid}

    <tr>

<td>{$Itemid[listt]}</td>

    </tr>

{/section}

.......

 

Now this generates something like this:

1

-

3

4

-

 

I'd like the result to be:

1

3

4

14

15

 

How can I change that? Where did I make a mistake?

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.