Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

assign array-in-array to a section

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Robbie
Smarty n00b


Joined: 20 Apr 2003
Posts: 4
Location: The Netherlands

PostPosted: Wed Apr 30, 2003 1:54 pm    Post subject: assign array-in-array to a section Reply with quote

Hi there!

I'm doing some testing with some mysql results and smarty.
But you will have to create an array of the result time after time, like this:
Code:
$query = mysql_query("SELECT * FROM news")or die(mysql_error());

$results = array();
while ( $row = mysql_fetch_array ( $query ) ) {
   $results[] = array(
      'id' => $row['id'],
      'subject' => $row['subject']
   );
}

$smarty->assign('results', $results);

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


and everytime I want to make another loop trough an different table I will have to change the 'id' and 'subject' etc etc.
well, I'm very lazy so I did some coding and the result is a piece of code that autom. run trough my mysql result and trow them in an array.

this is my code:
http://www.bloodyhound.net/area51/test.phps

using this template:
http://www.bloodyhound.net/area51/templates/test.tpl

and the result:
http://www.bloodyhound.net/area51/test.php

But you wil see that the array $result has 2 arrays in him.
After looping' and while-ing' I assign $result to my template, but it only assings the first array of $result.

I hope you understand it and have a solution for me.

ty, Robbie
Back to top
View user's profile Send private message Visit poster's website
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Wed Apr 30, 2003 3:51 pm    Post subject: Reply with quote

mysql_fetch_array returns every column TWO times - one time with numeric index, one time with associative index.
you should always use either mysql_fetch_assoc or mysql_fetch_row to avoid problems with that
Back to top
View user's profile Send private message
Robbie
Smarty n00b


Joined: 20 Apr 2003
Posts: 4
Location: The Netherlands

PostPosted: Wed Apr 30, 2003 4:34 pm    Post subject: Reply with quote

mysql_fetch_assoc doesn't make any change at all... Sad
what I'm doing wrong?

http://www.bloodyhound.net/area51/test.php
http://www.bloodyhound.net/area51/test.phps
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Apr 30, 2003 5:57 pm    Post subject: Reply with quote

but it *does* make a change.

your test-page show, you get a 2 dimensional array with 2 rows and 2 colums. this should be what you want.

with mysql_fetch_array() you will get an array with 2 rows, but 4 columns.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Robbie
Smarty n00b


Joined: 20 Apr 2003
Posts: 4
Location: The Netherlands

PostPosted: Wed Apr 30, 2003 7:14 pm    Post subject: Reply with quote

ah, indeed you r right, but how to fix my script then?
its still asigning only the first...
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General 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