第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 wordpress $wpdb insdie 短代碼顯示 <table> 內數(shù)據(jù)庫中的數(shù)據(jù)

使用 wordpress $wpdb insdie 短代碼顯示 <table> 內數(shù)據(jù)庫中的數(shù)據(jù)

PHP
滄海一幻覺 2024-01-19 16:54:20
下面的代碼不帶格式打印到一個塊中。鑒于短代碼已經(jīng)運行 php,我是否正確指定了 html?感覺不太像,因為 HTML 部分似乎不適合我。它只是作為整個塊輸出。(見圖)   function trying_2() {    '    <table border="1">    <tr>     <th>name</th>     <th>partysize</th>     <th>phonenumber</th>    </tr>';    global $wpdb;// sending query $result = $wpdb->get_results ("SELECT *  FROM table_name");    foreach ( $result as $print )   {      echo '<tr>';      echo '<td>' . $print->name.'</td>';      echo '<td>' . $print->partysize.'</td>';      echo '<td>' . $print->phonenumber.'</td>';      echo '<td>' . $print->emailaddress.'</td>';        echo '<td>' . $print->Time_stamp.'</td>';        echo '<td>' . $print->currentstatus.'</td>';    '</tr>';    } '</table>';}add_shortcode('tryin', 'trying_2');
查看完整描述

1 回答

?
九州編程

TA貢獻1785條經(jīng)驗 獲得超4個贊

您沒有正確格式化HTML/ table,因此為什么您在 WordPress 頁面上將所有內容打印在一行中。


您不需要分別回顯每一個td。您只需在您的variableto be和 中包裝一個定義,然后使用即可,并且只需將循環(huán)數(shù)據(jù)連接到該變量即可。echoedfunction


只需將其粘貼code到您的活動主題functions.php文件中,然后[tryin]在頁面中調用您的短代碼即可。(代碼經(jīng)過測試并且有效)


function trying_2() {


    global $wpdb;

    

    $results = '<table border="1">

            <thead>

                <tr>

                    <th>name</th>

                    <th>partysize</th>

                    <th>phonenumber</th>

                    <th>emailaddress</th>

                    <th>Time_stamp</th>

                    <th>currentstatus</th>

                </tr>

            </thead>

        <tbody>';


        // sending query

        $WPQuery = $wpdb->get_results ("SELECT * FROM table_name");

            foreach ( $WPQuery as $print )   {

                $results .= "<tr>

                            <td>$print->name</td>

                            <td>$print->partysize</td>

                            <td>$print->phonenumber</td>

                            <td>$print->emailaddress</td>

                            <td>$print->Time_stamp</td>

                            <td>$print->currentstatus</td>

                        </tr>";

                    }

                $results .= "</tbody>

    </table>";

    //Print results

    echo $results;

}


add_shortcode('tryin', 'trying_2');


查看完整回答
反對 回復 2024-01-19
  • 1 回答
  • 0 關注
  • 115 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號