Hi Linchen,
thanks for your question.
You have to be careful with variables here: Where (in what scope) does the $hallo variable exist? Was it defined directly inside the table cell? Or is defined outside of the cell? In that case, you will need to make it global, with a statement like this:
global $hallo;
at the beginning of your cell.
Also, there is an important thing that you have to keep in mind when using the PHP Extension in WP-Table Reloaded 1.9.1:
You must turn of table output caching for all tables that use PHP (otherwise your PHP code will only be executed once daily), by unchecking the corresponsing checkbox on the table’s “Edit” screen.
Regards,
Tobias
Thanks Tobias
if i write in my Post <?php echo $hallo;?> everything is fine
but if i write this in the table cell with global or without the cell is empty. Turn off caching ? Where ?
Regards
Linchen
Me again
Cache Table Output: The resulting HTML output of the table shall be cached in the WordPress database cache for faster page generation.
is not activated.
Regards
Linchen
Hi,
ok, thanks for testing this.
Not sure, why this is happening then… Where is $hallo defined or filled with content?
And: Do you get any PHP errors somewhere, e.g. in the error log on your server?
You might also need to set the “WP_DEBUG” constant to true in your wp-config.php to see errors.
Can you try that?
Regards,
Tobias
Hello Tobias
thanks for your answer.
For show php in the posts i use the plugin PHP Execution.
I have to include the include.php in every post for use the variables.
The Error Log is empty.
I put a table in the widget (text), maybe thats the problem ?
Regards
Linchen
Hi
i installed PHP code widget now, but same result.
<?php
include_once('include.php');
echo "$hallo";
[table id=8 /]
?>
Regards
Linchen
Hi,
thanks for that description.
Now I’m a little bit confused 🙂 So, you are having a plugin to use PHP in posts, and my Extension to use PHP in table cells, right?
In the code you posted, you are using a Shortcode inside of PHP. This will never work though, as Shortcodes have nothing to do with PHP. You should actually get a PHP parse error from that.
Did you mean
<?php
include_once('include.php');
echo "$hallo";
?>
[table id=8 /]
But then, what is the PHP code in the table cells of table 8?
You might also need to use include() instead of include_once(), so that your file is actually included every time. Otherwise the variables will not exist in the function’s scope.
Tobias
Hello Tobias
i was trying the include.php is included or not in the widget.
Sorry for my not really good description.
This is correct
<?php
include_once('include.php');
echo "$hallo";
?>
[table id=8 /]
Include php
<?php $hallo="hallo";?>
Widget
<?php
include_once('include.php');
echo "$hallo";
?>
[table id=8 /]
Table 8 (cell)
echo "$hallo";
Widget is empty, cell is empty
Regards
Linchen
Hi,
ok, thanks for the clarification.
Please try this:
include.php
<?php $hallo="hallo";?>
widget (no PHP here!)
[table id=8 /]
cell (with the PHP extension for WP-Table Reloaded enabled)
<?php
include( 'include.php' );
echo $hallo;
?>
(Note: I’m not sure right now, where the include.php needs to be located, so that the include call can find it. You might need to experiment with some “../..” in front of the file name, or use an absolute path.)
Tobias
Hallo Tobias
thanks for your patience
your cell code show me a error:
Parse error: syntax error, unexpected '>' in /httpdocs/wp-content/plugins/wp-table-reloaded-extensions.php(16) : eval()'d code on line 1
Regards
Linchen
Hello again
the problem is the include of the file this example work
<?php
$hallo="hallo";
echo $hallo;
?>
Regards
Linchen
Hi Linchen,
yes, as I said, the location of the include.php is important.
I’m not sure how file inclusion in terms of the file path is handled in eval().
Try this PHP:
<?php
echo __FILE__;
?>
This should result in something like “/www/user/httpdocs/wp-content/plugins/wp-table-reloaded-extensions.php”.
Then take the first part of that and adjust it to the path for the include.php, probably something like “/www/user/httpdocs/include.php”, if your include.php is in the main directory of WordPress.
Then use that path in the include() call, i.e.
<?php
include( 'www/user/httpdocs/include.php' );
echo $hallo;
?>
Regards,
Tobias
Hello Tobias
i tryed with absolute path, with http path and all what i found in the internet but it doesnt work.
Regards
Linchen
Hi,
ok. If you want, I can take a direct look at it in your admin area.
For that, can you email me (address is in the main plugin file “wp-table-reloaded.php”)?
Regards,
Tobias
Hi
i found the problem, it works only if you use php without space`<?php
include(‘www/user/httpdocs/include.php’);echo $hallo;?>`
Thanks
Linchen