0

Я хочу получить в Админ панеле только несколько идентификаторов из MySql на php.

Вот пример из MySql в картинке

А это мой код:

    // create array variable to store data from database
    $data = array();

    if(isset($_GET['keyword'])){    
        // check value of keyword variable
        $keyword = $function->sanitize($_GET['keyword']);
        $bind_keyword = "%".$keyword."%";
    }else{
        $keyword = "";
        $bind_keyword = $keyword;
    }

    // get currency symbol from setting table
    $sql_query = "SELECT Value 
            FROM tbl_setting 
            WHERE Variable = 'Currency'";

    $stmt = $connect->stmt_init();
    if($stmt->prepare($sql_query)) {    
        // Execute query
        $stmt->execute();
        // store result 
        $stmt->store_result();
        $stmt->bind_result($currency);
        $stmt->fetch();
        $stmt->close();
    }   

    // get all data from menu table and category table
    if(empty($keyword)){
        $sql_query = "SELECT Menu_ID, Menu_name, Category_name, Price, Serve_for, Menu_image, Quantity 
                FROM tbl_menu m, tbl_category c
                WHERE m.Category_ID = c.Category_ID  
                ORDER BY m.Menu_ID DESC";
    }else{
        $sql_query = "SELECT Menu_ID, Menu_name, Category_name, Price, Serve_for, Menu_image, Quantity  
                FROM tbl_menu m, tbl_category c
                WHERE m.Category_ID = c.Category_ID AND Menu_name LIKE ? 
                ORDER BY m.Menu_ID DESC";
    }

    $stmt = $connect->stmt_init();
    if($stmt->prepare($sql_query)) {    
        // Bind your variables to replace the ?s
        if(!empty($keyword)){
            $stmt->bind_param('s', $bind_keyword);
        }
        // Execute query
        $stmt->execute();
        // store result 
        $stmt->store_result();
        $stmt->bind_result($data['Menu_ID'], 
                $data['Menu_name'], 
                $data['Category_name'],
                $data['Price'], 
                $data['Serve_for'],
                $data['Menu_image'],
                $data['Quantity']
                );

        // get total records
        $total_records = $stmt->num_rows;
    }

    // check page parameter
    if(isset($_GET['page'])){
        $page = $_GET['page'];
    }else{
        $page = 1;
    }

    // number of data that will be display per page     
    $offset = 10;

    //lets calculate the LIMIT for SQL, and save it $from
    if ($page){
        $from   = ($page * $offset) - $offset;
    }else{
        //if nothing was given in page request, lets load the first page
        $from = 0;  
    }

    // get all data from reservation table
    if(empty($keyword)){
        $sql_query = "SELECT Menu_ID, Menu_name, Category_name, Price, Serve_for, Menu_image, Quantity  
                FROM tbl_menu m, tbl_category c
                WHERE m.Category_ID = c.Category_ID  
                ORDER BY m.Menu_ID DESC LIMIT ?, ?";
    }else{
        $sql_query = "SELECT Menu_ID, Menu_name, Category_name, Price, Serve_for, Menu_image, Quantity  
                FROM tbl_menu m, tbl_category c
                WHERE m.Category_ID = c.Category_ID AND Menu_name LIKE ? 
                ORDER BY m.Menu_ID DESC LIMIT ?, ?";
    }

    $stmt_paging = $connect->stmt_init();
    if($stmt_paging ->prepare($sql_query)) {
        // Bind your variables to replace the ?s
        if(empty($keyword)){
            $stmt_paging ->bind_param('ss', $from, $offset);
        }else{
            $stmt_paging ->bind_param('sss', $bind_keyword, $from, $offset);
        }
        // Execute query
        $stmt_paging ->execute();
        // store result 
        $stmt_paging ->store_result();

        $stmt_paging->bind_result($data['Menu_ID'], 
                $data['Menu_name'], 
                $data['Category_name'],
                $data['Price'], 
                $data['Serve_for'],
                $data['Menu_image'],
                $data['Quantity']
                );

        // for paging purpose
        $total_records_paging = $total_records; 
    }

    // if no data on database show "No Reservation is Available"
    if($total_records_paging == 0){
3
  • 1
    AND c.Category_ID IN (1,2,3,4,5.....N) в WHERE добавить
    – sterx
    9 фев 2019 в 5:40
  • Спасибо большое sterx . Это работает.
    – Shih
    9 фев 2019 в 5:57
  • @sterx как ответ оформите (: 9 фев 2019 в 7:21

1 ответ 1

1

AND c.Category_ID IN (1,2,3,4,5.....N) в WHERE добавить

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.