Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在shortcode中显示html表格数据库-Wordpress_Php_Mysql_Wordpress_Plugins - Fatal编程技术网

Php 在shortcode中显示html表格数据库-Wordpress

Php 在shortcode中显示html表格数据库-Wordpress,php,mysql,wordpress,plugins,Php,Mysql,Wordpress,Plugins,我在数据库中有一个包含HTML()的表。 我正在正确地检索它,我试图用这个数据生成一个短代码,但它不能正常工作。我在谷歌上做了很多研究,但什么都找不到。。。这是我的密码 public static function fln_table_shortcode() { global $wpdb; //$table_name=$wpdb->prefix.'generated_tables'; $results = $wpd

我在数据库中有一个包含HTML()的表。 我正在正确地检索它,我试图用这个数据生成一个短代码,但它不能正常工作。我在谷歌上做了很多研究,但什么都找不到。。。这是我的密码

public static function fln_table_shortcode() {

            global $wpdb;
            //$table_name=$wpdb->prefix.'generated_tables';

            $results = $wpdb->get_results( 'SELECT * FROM wp_generated_tables WHERE table_id = 7',OBJECT );

            foreach ($results as $data) {

                foreach ($data as $key=>$value){
                    if($key =="html_table"){
                         $content = $value;

                    }
                }


                }



            }


        $striped = stripslashes($content);
            return $striped";// this var contains html code <table>
            //echo $striped." this is the table";
        }

    public static function fln_register_shortcodes() {
        add_shortcode( 'table_shortcode', array( 'FinancialShortcodes', 'fln_table_shortcode' ) );
    }
公共静态函数fln\u table\u shortcode(){
全球$wpdb;
//$table_name=$wpdb->prefix.'generated_tables';
$results=$wpdb->get_results('SELECT*FROM wp_-generated_-tables,其中table_-id=7',OBJECT);
foreach($结果作为$数据){
foreach($key=>$value形式的数据){
如果($key==“html\u表”){
$content=$value;
}
}
}
}
$striped=stripeslashes($content);
返回$striped”;//此变量包含html代码
//echo$striped.“这是桌子”;
}
公共静态函数fln_寄存器_短码(){
添加_短代码('table_shortcode',数组('FinancialShortcodes','fln_table_shortcode');
}
有什么想法吗?请帮忙


提前感谢。

试试这段代码,将其添加到functions.php中

function fln_table_shortcode() {
        global $wpdb;
        //$table_name=$wpdb->prefix.'generated_tables';

        $results = $wpdb->get_results( 'SELECT * FROM wp_generated_tables WHERE table_id = 7',OBJECT );
        $content = "";
        foreach ($results as $data) {
            foreach ($data as $key=>$value){
                if($key =="html_table"){
                     $content .= stripslashes(html_entity_decode($value));
                }
            }
        }
        return $content;
}
add_shortcode( 'table_shortcode','fln_table_shortcode');

希望这能对你有所帮助。

Jesus,你为什么要将HTML存储在数据库中?你可以使用模板引擎或其他引擎轻松地遍历数据。如果你可以访问运行wordpress的服务器,只需安装一个模板引擎,它将非常结构化和容易。这是有原因的,因为css功能将我需要发展