php nub has simple echo question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psispaz
Forum Newbie
Posts: 4
Joined: Mon Apr 21, 2003 9:09 pm

php nub has simple echo question

Post by psispaz »

Is it possible to echo an echo? Such as if the echo code is inside a mysql database field?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

No.

You might want to look at eval() though.
psispaz
Forum Newbie
Posts: 4
Joined: Mon Apr 21, 2003 9:09 pm

nother nub question

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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);
}
?>
Last edited by McGruff on Thu Aug 11, 2005 11:13 am, edited 1 time in total.
psispaz
Forum Newbie
Posts: 4
Joined: Mon Apr 21, 2003 9:09 pm

way tight

Post by psispaz »

hey thanks guys one of those should work, I hope, atleast it gives me some more stuff to work with
psispaz
Forum Newbie
Posts: 4
Joined: Mon Apr 21, 2003 9:09 pm

uber nUb question [part III] WOW!!1

Post 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?
Post Reply