Jump to content


Photo

loop question


  • Please log in to reply
2 replies to this topic

#1 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 02 April 2006 - 02:18 AM

hi,

probabley a dumb question but I'm curious about this.

i have a template class created and its pretty good though it has one limitation, loops. it doesnt work well at all with loops. my solution place the loops in a function and call them in the template, it works.

but it seems to kill off the customablity a bit which is where this question comes in.

is there a way to draw out the variables made by the loop by plaxcing them into an array?

hard to phrase this so i'll write out an example of what i mean:

function loop_thing(){
//sql query stuff here
while($row = mysql_fetch_assoc($sql_r)){

$results = array($row['colume1'], $row['Colume2'], $row['colume3']);
}
return $results;
}
//then to output:
$results = loop_thing();

echo $result[0]. "<br>";
echo $result[1]. "<br>";
echo $result[2];

would something like that work?

thanks.

#2 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 02 April 2006 - 03:17 AM

Yes, you can do this
Same script but modified

function loop_thing(){
//sql query stuff here
$results = array();
$i = 0;
while($row = mysql_fetch_array($sql_r, MYSQL_NUM)){
     $results[] = $row[$i];
}
return $results;
}
//then to output:
$results = loop_thing();

echo $result[0]. "<br>";
echo $result[1]. "<br>";
echo $result[2];

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#3 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 02 April 2006 - 04:42 AM

thats great to hear :D

thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users