php nub has simple echo question
Moderator: General Moderators
php nub has simple echo question
Is it possible to echo an echo? Such as if the echo code is inside a mysql database field?
nother nub question
Ok, i was researching eval to no avail, code is hard....but here is a better description of my problem, maybe one of the gurus can point me in the right direction.
ok i've got 130 things for sale on my site, I have one php page that calls all the info about each product (name price description etc.) and prints it out.
now, each product has up to 3 different ways to be purchased, although some products only have 1 or 2 options for purchase.
each option has its own dynamicly created buy button from info in the database, (price name etc)
so in layout the page looks like
Product Name
Product Info
optionA - (button)
optionB - (button)
optionC - (button)
now this is where it gets fun, when a product only has 2 options I need the page to only make 2 buttons.
what i've done to try and make this work so far is to simply put the button code in a mysql database field then echo the code, but the button code inside the database field contains <? echo"$var"; ?> inside of it. When I try to echo that field it just prints out "> "> "> where the button should be. I know i'm doing something wrong but I don't know what.
ok i've got 130 things for sale on my site, I have one php page that calls all the info about each product (name price description etc.) and prints it out.
now, each product has up to 3 different ways to be purchased, although some products only have 1 or 2 options for purchase.
each option has its own dynamicly created buy button from info in the database, (price name etc)
so in layout the page looks like
Product Name
Product Info
optionA - (button)
optionB - (button)
optionC - (button)
now this is where it gets fun, when a product only has 2 options I need the page to only make 2 buttons.
what i've done to try and make this work so far is to simply put the button code in a mysql database field then echo the code, but the button code inside the database field contains <? echo"$var"; ?> inside of it. When I try to echo that field it just prints out "> "> "> where the button should be. I know i'm doing something wrong but I don't know what.
although I don't think having the code within the table is a good idea
tryas example
try
Code: Select all
<?php
$stat = 'echo $var;';
$var = 'test';
?>
<pre style="border: 1px solid silver;">
<?php echo $stat; ?>
</pre>
<pre style="border: 1px solid silver;">
<?php eval($stat); ?>
</pre>Suppose, in the product table, you had a button option column. Column stores "A B C" or "A B" - whatever is appropriate.
When you query the table to get product info you can explode the button data to get an array:
Can you write a draw_button() function which takes A, B or C as an argument? If so:
When you query the table to get product info you can explode the button data to get an array:
Code: Select all
<?php
$options = explode(' ', $result['button']);
?>Code: Select all
<?php
foreach ($options as $value) {
draw_button($value);
}
?>
Last edited by McGruff on Thu Aug 11, 2005 11:13 am, edited 1 time in total.
uber nUb question [part III] WOW!!1
Hey guys, me again, one of those examples probably does this but I can't quite figure them out yet. Would it be easier to store the button code in a variable on the product page?