Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding PHP variable to product description


ollyno1uk2

Recommended Posts

Posted

I have been trying to add a php vairable directly into the table products_description.products_description but it does not work as I had hoped.

 

Am I not considering another factor that could stop this working?

 

Thanks in advance

Posted

I don't think you can put a php inside php.

 

<?php echo stripslashes($product_info['products_description']); ?>

 

Try it without adding an additional php tag or close the php tag and then reopen it.

 

?><?php my variable ?><php

 

Not sure if that will work, I have never tried it.

Posted

Post your PHP code.

 

Sounds like you have a slight syntax problem.

 

You don't need to post the whole page, just the little snippet that's giving you problems.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Posted

Hi thanks

 

It is a simple addition

 

<hr><br>
<table>
<tr>
<td class = "smalltext">


<?php echo $rrp; ?>
</td>
</tr>
</table>
<br>
<hr>

 

This is dropped into the description and shows the RRP - the variable works anywhere on the products_info.php page but not if I insert into the table within the products description text

Posted

could I perhaps do it another way and show only the product description up to a certain word, then echo the string within product_info.php and then run a final echo of the remaining products_description field?

 

Maybe this is a long winded way of doing it but I'm not sure how to try it.

 

Thanks

Posted

There is html with PHP inclusions and html parsed by PHP they have two seperate syntax.

 

PHP inclusions:

 

<table>
 <tr>
<td><?php echo $imavariable; ?></td>
 </tr>
</table>

 

HTML parsed by PHP

 

<?php
echo '
<table>
 <tr>
<td>' . $imavariable . '</td>
 </tr>
</table>';
?>

 

You also have to be aware of how quotes are being used because the above can also be written ..

 

<?php
echo "
<table>
 <tr>
<td>$imavariable</td>
 </tr>
</table>";
?>

 

The difference being the use of single or double opening/closing quotes.

 

Hope that helps

Posted

Without seeing more code, all I can think of is an alignment problem.

 

Maybe this:

 

<td class = "smalltext">

Needs to be something like:

 

<td class = "smalltext" align="center">

:unsure:

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Posted

I think what I am doing is correct but as the php is within the products_decsription table, it doesn't respond for some reason

Posted
I think what I am doing is correct but as the php is within the products_decsription table, it doesn't respond for some reason

 

If what you were doing was correct it would work :)

Posted

Lol - yes that is true!

 

here i some more code as I don't get it - this is direct fromthe products_description table and products_description field.

 

<p>text heret.</p><br><br>
<hr><br>
<table>
<tr>
<td class = "smalltext" align = "center"> <?php echo '123'; ?>
</td>
</tr>
</table>
<br>
<hr>
<br>

<br><B>Specs</B>...................

 

I have made it 123 to make it easier to see where it is going wrong and nothing is outputted.

 

Thanks a lot

Posted
This is dropped into the description and shows the RRP - the variable works anywhere on the products_info.php page but not if I insert into the table within the products description text

 

What do you mean "within the products description text" are you talking about adding text in admin?

Posted

Do something like this:

 

<hr><br>
<table>
<tr>
<td class = "smalltext">

<!-- here is my PHP variable -->
<?php echo $rrp; ?>
<!-- there was my PHP variable -->
</td>
</tr>
</table>
<br>
<hr>

Then look at the HTML source for those comments.

 

That will ensure PHP is getting to your code.

 

I have no further suggestions without more code to look at, or a URL to visit to see for myself.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Posted

The source results in an empty table cell.

 

FWR - yes I am inserting the php into the table field iteself within the text of that field. In products_description.products_description

Posted
The source results in an empty table cell.

 

FWR - yes I am inserting the php into the table field iteself within the text of that field. In products_description.products_description

 

You wont get it to work.

 

You can't add PHP code via admin nor through MySQL.

 

You could get it to work by adding a placeholder then replacing it with the variable via str_replace in the outputting file.

Posted

Ah right - this was my suspicion - Is there a way around it? Or is it inbuilt to OSC?

 

What are my options as far as attempting to split the text of products_description so I can insert the variable into products_info.php in between the two halves?

 

Thanks for your help BTW

Posted
Ah right - this was my suspicion - Is there a way around it? Or is it inbuilt to OSC?

 

What are my options as far as attempting to split the text of products_description so I can insert the variable into products_info.php in between the two halves?

 

Thanks for your help BTW

 

Here is an example: -

 

<?php
$text = 'This is some text ---placeholder--- this is some more text';
$replace = 'I replaced the placeholder';
$text = str_replace('---placeholder---', $replace, $text);
echo $text;
?>

Posted

In product_info.php it would look like the following: -

 

I found this line . .

 

		  <p><?php echo stripslashes($product_info['products_description']); ?></p>

 

 

It would look like ...

 

		  <p>
	  <?php
	  $myvar = '123';  // Hopefully this wouldn't be hardcoded
	  if (isset($myvar)) { // In case it is optional
	  $product_info['products_description'] = str_replace('---placeholder---', $myvar, $product_info['products_description']);
	  }
	  echo stripslashes($product_info['products_description']);
	  ?>
	  </p>

Posted

Yes this does seem to work well - this means I can now ge back to editing only the product_info.php - that is really top stuff - thanks a lot - learnt something new as well!

 

Cheers

  • 1 month later...
Posted

Hi

 

I know no one has added to this thread for a few weeks but can you help me.

 

I want to add an extra field between the Product Name and Product Price, I worked out where it has to go and have put a table cell there and inputed some text to make sure this is correct place.

 

I have created the field in the products table and called it products_weightdisplay, what I need is depending on the product to have a choice of three text fields that will relate the price either to a kilo price, a pack price and another one.

 

I've hunted through the contributions and forums and can't find anything that totally matches my requirements.

 

Any help is greatly appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...