Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Smarty array with a sql db?

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
KyleFYI
Smarty n00b


Joined: 25 Mar 2012
Posts: 1

PostPosted: Sun Mar 25, 2012 5:40 pm    Post subject: Smarty array with a sql db? Reply with quote

Okay I want to do a array and grab the items from a sql db.
This is what I have so far.

PHP
Code:

$query = mysql_query('SELECT * FROM user');
$data = array('users');
while($row = mysql_fetch_assoc($query)) {
$data['users'][] = $row[];
}


TPL
Code:

<html>
{foreach $users as $row}
{$row.username}
{$row.email}
{/foreach}
</html> 


But it comes up with this error.
Fatal error: Cannot use [] for reading in C:\xampp\htdocs\sdb\admin\users.php on line 6
I can't seem to fix it.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4673
Location: Hamburg / Germany

PostPosted: Sun Mar 25, 2012 8:22 pm    Post subject: Reply with quote

Code:
$query = mysql_query('SELECT * FROM user');
$data = array('users');
while($row = mysql_fetch_assoc($query)) {
$data['users'][] = $row;
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP