Forum Moderators: coopster

Message Too Old, No Replies

Urgent smarty problem

some smarty problem

         

maradox

11:25 pm on Apr 13, 2009 (gmt 0)

10+ Year Member



I have in a table one rows data

this is my php code:


$images=$data->exec_fetch_assoc("SELECT id, username, email, name, surname, status FROM main_users ORDER BY id ASC");
$tpl->assign("images",$images);
$tpl->display("adm_userlist.tpl");

when I do a var_dump I get this:

array(6) { ["id"]=> string(1) "3" ["username"]=> string(8) "MaradoXx" ["email"]=> string(14) "email" ["name"]=> string(7) "Provost" ["surname"]=> string(10) "Sebastiaan" ["status"]=> string(1) "4" }

and this is in my html template:

{foreach from=$images item=imagek name=imgs}
<tr>
<td width="5%">{$imagek.id}</td>
<td width="15%">{$imagek.username}</td>
<td width="15%">{$imagek.email}</td>
<td width="25%">{$imagek.name} &nbsp; {$imagek.surname}</td>
<td width="15%">{$imagek.status}</td>
</tr>
{foreachelse}
<tr>
<td colspan=5>
<center>No users registered</center>
</td>
</tr>
{/foreach}

and this is what I get as a result? >.<:

Can somebody help me? :(
it clearly gives 6 rows (there are 6 fields used in the array) and from each value in the array the first char. Does somebody knows what I am doing wrong?

also this is the function to get the data out of the db:


function exec_fetch_assoc($query_string)
{
if($this->query_string <>"" && $query_string == "")
{
self::exec_query($this->query_string);
}
else
{
self::exec_query($query_string);
}
$this->end_result=mysql_fetch_assoc($this->result);
return $this->end_result;
}

[edited by: eelixduppy at 1:45 am (utc) on April 14, 2009]
[edit reason] removed screenshot url [/edit]

bkeep

12:14 am on Apr 14, 2009 (gmt 0)

10+ Year Member



change your foreach clause to use it with just the basic foreach to test it without the foreachelse


{foreach item="imagek" from=$images}
<tr>
<td width="5%">{$imagek.id}</td>
<td width="15%">{$imagek.username}</td>
<td width="15%">{$imagek.email}</td>
<td width="25%">{$imagek.name} &nbsp; {$imagek.surname}</td>
<td width="15%">{$imagek.status}</td>
</tr>
{/foreach}

I would start there then see what your output is

maradox

6:48 am on Apr 14, 2009 (gmt 0)

10+ Year Member



That gives me the same problem.
And I also just found out, my table has 2 rows of data and it only gets one with that query? >.<

Does somebody know whats wrong?

Little_G

9:18 am on Apr 14, 2009 (gmt 0)

10+ Year Member



Hi,

It looks like your exec_fetch_assoc method is returning only one row, that's what needs to be fixed.

Andrew

rocknbil

5:17 pm on Apr 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Little_G is correct, and the display is probably only the last row found; try a while loop.

while ($images=$data->exec_fetch_assoc("SELECT id, username, email, name, surname, status FROM main_users ORDER BY id ASC")) {
// your foreach and output code here
}