Jump to content

Archived

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

darkcarnival

loop question

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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.