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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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