duancaiyi7567 2017-12-19 07:58
浏览 33
已采纳

如何仅显示值为0的项目?

I am creating a plug-in for WordPress. With this plug-in, the admin can insert from the backend a project. These projects always get a value of "0" in the database.

From the ui everybody can insert a project to, but these projects get a value of "1" in the database.

I only want to display the projects with the value of "0" on a page in the GUI.

with this code, I get the database items in my class.

public function getProjectenList() {

    global $wpdb;
    $return_array = array();

    $result_array = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . 
      "ivs_canvas_tabel` ORDER BY `id`", ARRAY_A);

This is the code in the view:

   <?php
    if ($projecten->getNrOfProjecten() < 1) {
        ?>
        <tr><td colspan="4">Voeg een project of media-uiting toe</tr>
        <?php
    } else {
        $cat_list = $projecten->getProjectenList();

        //** Show all projects in the tabel
        foreach ($cat_list as $project_obj) {
            // Create update link
            $params = array('action' => 'update', 'id' => $project_obj->getId());
            // Add params to base url update link
            $upd_link = add_query_arg($params, $base_url);

            // Create delete link
            $params = array('action' => 'delete', 'id' => $project_obj->getId());
            // Add params to base url delete link
            $del_link = add_query_arg($params, $base_url);
            ?>

            <tr><td width="10" style="vertical-align: top;"><?php echo $project_obj->getId(); ?>
                </td>
                <?php
                // If update and id match show update form
                // Add hidden field id for id transfer
                if (($action == 'update') &&
                        ($project_obj->getId() == $get_array['id'])) {
                    ?> 
                    <td width="150" style="vertical-align: top;"><input type="hidden" name="id" value="<?php echo $project_obj->getId(); ?>">
                        <input type="text" name="naam" value="<?php echo $project_obj->getNaam(); ?>"></td>
                    <td width="10" style="vertical-align: top;"><input type="text" name="level" value ="<?php echo $project_obj->getLevel(); ?>"></td>
                    <td width="300" style="vertical-align: top;"><textarea name="beschrijving" maxlength="200"> <?php echo $project_obj->getBeschrijving(); ?></textarea></td>
                    <td><input type='file' name='afbeelding' value="<?= IVS_CANVAS_PLUGIN_INCLUDES_UPLOAD_IMGS_DIR_URL . $project_obj->getAfbeelding() ?>"></td>


                    <td colspan="2"><input type="submit" name="update" 
          value="Updaten"/></td>
                <?php } else { ?>
                    <td width="150" style="vertical-align: top;"><?php echo 
          $project_obj->getNaam(); ?></td>
                    <td width="10" style="vertical-align: top;"><?php echo 
        $project_obj->getLevel(); ?></td>
                    <td width="300" style="vertical-align: top;"><?php echo $project_obj->getBeschrijving(); ?></td>
                    <td width="100"><img src="<?= IVS_CANVAS_PLUGIN_INCLUDES_UPLOAD_IMGS_DIR_URL . $project_obj->getAfbeelding() ?>" width="100px" height="100px"/></td></td>



                    <?php
                    if ($action !== 'update') {
                        // If action is update don’t show the action button
                        ?>
                        <td><button><a href="<?php echo $upd_link; ?
       >">Wijzigen</a></button></td>
                        <td><button><a href="<?php echo $del_link; ?
       >">Verwijderen</a></button></td>
                        <?php
                    } // if action !== update
                    ?>

                <?php } // if acton !== update  ?>                   


            </tr>
            <?php
        }
    }
    ?>

The table structure

   $sql = "CREATE TABLE $table_name (
        id int (100) NOT NULL AUTO_INCREMENT,
        naam varchar (255) NOT NULL,
        level int (10) NOT NULL,
        beschrijving varchar (1024) NOT NULL,
        afbeelding varchar(1024) NOT NULL,
        status int (1) NOT NULL,
        PRIMARY KEY  (id)

)

I hope someone can help me out!

  • 写回答

1条回答 默认 最新

  • dongya2030 2017-12-19 08:56
    关注

    If you only want the project with value in some column is 0 you can add where filter in your query

    $result_array = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "ivs_canvas_tabel` WHERE some_column = 0 ORDER BY `id`", ARRAY_A);
    

    The above will return you only projects where some_column is zero, Use your column name in place if some_column which has this flag for admin projects and user projects

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?