Jump to content


Photo

Can you assign while to a var?


  • Please log in to reply
5 replies to this topic

#1 flamerail

flamerail
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 21 May 2006 - 12:44 AM

Im trying to generate a table with while then assign it to a var for later use. Is it possible?

Also whats up with the phpfreaks chat? Its dead... is there an irc chat for us any where?

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 21 May 2006 - 01:01 AM

I don't know why you'd really want to do that, however, any PHP can be assigned to a variable and executed at run time using eval().

[a href=\"http://us2.php.net/manual/en/function.eval.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.eval.php[/a]

I'll report the chat being down. Thanks.


#3 flamerail

flamerail
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 21 May 2006 - 01:56 AM

[!--quoteo(post=375613:date=May 20 2006, 09:01 PM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ May 20 2006, 09:01 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I don't know why you'd really want to do that, however, any PHP can be assigned to a variable and executed at run time using eval().

[a href=\"http://us2.php.net/manual/en/function.eval.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.eval.php[/a]

I'll report the chat being down. Thanks.
[/quote]

That isnt doing quiet what I needed but thanks.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 02:05 AM

well if you are looking to do like,

$blah = 'while';

$x = 0;
$blah ($x < 10) {
..
.
$x++;
}

the closest you are going to get is by using eval.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 jeremywesselman

jeremywesselman
  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts
  • LocationIndependence, KY

Posted 21 May 2006 - 02:26 AM

Why don't you put the code to generate the table into a function. Then you can call the function when you are ready to use the code in it.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 02:32 AM

oh wait, i get it. so you want to do something like this:

$x = 0;

$blah = "<table>";
while ($x < 10) {
   $blah.= "<tr><td>" . $x . "</td></tr>";
   $x++;
}

$blah.="</table>";

echo $blah;
$blah is a string that holds the entire table and contents.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users