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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.