Page 1 of 1
php nub has simple echo question
Posted: Mon Apr 21, 2003 9:09 pm
by psispaz
Is it possible to echo an echo? Such as if the echo code is inside a mysql database field?
Posted: Mon Apr 21, 2003 10:56 pm
by McGruff
No.
You might want to look at eval() though.
nother nub question
Posted: Tue Apr 22, 2003 11:15 am
by psispaz
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.
Posted: Tue Apr 22, 2003 11:51 am
by volka
although I don't think having the code within the table is a good idea
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>
as example
Posted: Tue Apr 22, 2003 2:12 pm
by McGruff
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:
Code: Select all
<?php
$options = explode(' ', $result['button']);
?>
Can you write a draw_button() function which takes A, B or C as an argument? If so:
Code: Select all
<?php
foreach ($options as $value) {
draw_button($value);
}
?>
way tight
Posted: Tue Apr 22, 2003 2:31 pm
by psispaz
hey thanks guys one of those should work, I hope, atleast it gives me some more stuff to work with
uber nUb question [part III] WOW!!1
Posted: Wed Apr 23, 2003 10:10 am
by psispaz
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?