1

I have the following php code:

$skizzar_masonry_item_width = $masonry_item_width;
$skizzar_masonry_item_padding = $masonry_item_padding;
$skizzar_double_width_size = $masonry_item_width*2 +$masonry_item_padding;

$output .= '<style>.skizzar_masonry_entry.skizzar_ma_double, .skizzar_masonry_entry.skizzar_ma_double img {width:'.$skizzar_double_width_size.'}</style>';

return $output;

For some reason though, the value of $skizzar_double_width_size is not being added into the $output - is there a way to echo a value in an output variable?

7
  • 2
    Did you initialize your $output variable with $output = ""; before you appended stuff? Commented Jan 19, 2015 at 14:51
  • @Rizier123 shouldn't make a difference if error_reporting is off. Commented Jan 19, 2015 at 14:52
  • Are you sure $skizzar_double_width_size has a value? Commented Jan 19, 2015 at 14:52
  • var_dump($skizzar_double_width_size) will tell you if there's anything in that var. And given your previous question, you really should sit down and study php syntax a bit better. "echo a value in an output variable"? Commented Jan 19, 2015 at 14:54
  • 1
    then do a view source on the page that contains this css. Most likely the value's there, but not working because you didn't include any units. width:485 in css is illegal. it should be width:485px or whatever. Commented Jan 19, 2015 at 15:04

2 Answers 2

1

As @Rizier123 mentioned, ensure you initialise any string variables before trying to append to them.

$var = ''; $var .= 'I appended'; $var .= ' a string!';

I would also like to strongly discourage you from using inline styles as well as generating them with inline PHP. Things get very messy very quickly.

Sign up to request clarification or add additional context in comments.

2 Comments

It doesn't make a difference if the variable is instantiated, yes you will get an error if error_reporting is on. However $output would still contain the value assigned.
From the looks of the original question, it's hard to determine whether the other variables have been defined at all so it's hard to really say much more than this. I'll expand with some debugging information. Actually looks like I don't have the rep so I'll have to do it here. If it's vanilla PHP he should check the value of variables that aren't being set correctly using either var_dump(), print_r() or echo and fire off die() to halt script execution. It's the only other explanation I can think of, either that or the code posted is in a function that isn't even called.
1

In a situation like this you need to check that all the variables you are using in the calculation are valid before you panic.

So try

echo 'before I use these values they contain<br>';
echo '$masonry_item_width = ' . $masonry_item_width . '<br>';
echo '$masonry_item_padding = ' . $masonry_item_padding . '<br>';


$skizzar_masonry_item_width = $masonry_item_width;
$skizzar_masonry_item_padding = $masonry_item_padding;
$skizzar_double_width_size = $masonry_item_width*2 +$masonry_item_padding;

echo 'after moving the fields to an unnecessary intemediary field<br>';
echo '$skizzar_masonry_item_width = ' . $skizzar_masonry_item_width . '<br>';
echo '$skizzar_masonry_item_padding = ' . $skizzar_masonry_item_padding . '<br>';
echo '$skizzar_double_width_size = ' . $skizzar_double_width_size . '<br>';


$output .= '<style>.skizzar_masonry_entry.skizzar_ma_double, .skizzar_masonry_entry.skizzar_ma_double img {width:'.$skizzar_double_width_size.'}</style>';

echo $output;

This should identify which fields are causing you problems.

Also while testing always run with display_errors = On It saves so much time in the long run.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.