Jump to content

loop question


darkcarnival

Recommended Posts

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:

[code]
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];[/code]

would something like that work?

thanks.
Link to comment
https://forums.phpfreaks.com/topic/6372-loop-question/
Share on other sites

Yes, you can do this
Same script but modified

[code]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];
[/code]
Link to comment
https://forums.phpfreaks.com/topic/6372-loop-question/#findComment-23061
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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