How to extract only columns which has non zero values in mysql and php?

后端 未结 1 1435
温柔的废话
温柔的废话 2021-01-29 09:12

I am trying to extract and display on web page, only non zero columns from mysql database. which ever column\'s date is 0000-00-00,i dont want to dispaly those columns on web p

1条回答
  •  盖世英雄少女心
    2021-01-29 09:34

    Try this:

    $result = mysqli_query($conn, "SELECT * FROM $dbname.statusinfo WHERE soid = '$userinput1' AND date_column <> '0000-00-00' ") or die(mysqli_error($conn));
    

    Although, with mysql you may even be able to do this:

    $result = mysqli_query($conn, "SELECT * FROM $dbname.statusinfo WHERE soid = '$userinput1' AND date_column > '0000-00-00' ") or die(mysqli_error($conn));
    

    Hope this helps

    EDIT

    I can see what you want now that you amended the question :) Unfortunately I do not know of a way to what you want using SQL (someone may).

    You are outputting the column headings and so not outputting a particular column would cause them to appear in the wrong columns so you will just have to output nothing where time is 0000-00-00

    This is how I would do it in PHP though. (and if I have missed your point again I may shoot myself :))

    connect_errno) {
            printf("Connect failed: %s\n", $conn->connect_error);
            exit();
        }
    
        $result = mysqli_query($conn, "SELECT * FROM $dbname.statusinfo WHERE soid = '$userinput1'  ") or die(mysqli_error($conn));
    
        $arrayHeadings = array(
            "dept"                  => "Department", 
            "samplerecived"         => "Sample Recived",
            "molbioextraction"      => "Mol-Bio Extraction",
            "molbioextractionqc"    => "Extraction QC",
            "libraryprep"           => "Library Prep",
            "libraryqc"             => "Library QC",
            "sequencing"            => "Sequencing",
            "datacheck"             => "Data Check",
            "resequencing"          => "RE Sequencing",
            "qccheck"               => "QC Check",
            "analysisstarted"       => "Analysis Started",
            "analysiscompleted"     => "Analysis Completed",
            "report"                => "Report",
            "outbound"              => "Outbound",
        );
    
    ?>
    
    
     $name): ?>
                 $name): ?>
                    

    EDIT

    The table headings are not output if the field contains 0000-00-00. This relies on only one element being output at a time.

    connect_errno) {
            printf("Connect failed: %s\n", $conn->connect_error);
            exit();
        }
    
        $result = mysqli_query($conn, "SELECT * FROM $dbname.statusinfo WHERE soid = '$userinput1'  ") or die(mysqli_error($conn));
    
        $arrayHeadings = array(
            "dept"                  => "Department", 
            "samplerecived"         => "Sample Recived",
            "molbioextraction"      => "Mol-Bio Extraction",
            "molbioextractionqc"    => "Extraction QC",
            "libraryprep"           => "Library Prep",
            "libraryqc"             => "Library QC",
            "sequencing"            => "Sequencing",
            "datacheck"             => "Data Check",
            "resequencing"          => "RE Sequencing",
            "qccheck"               => "QC Check",
            "analysisstarted"       => "Analysis Started",
            "analysiscompleted"     => "Analysis Completed",
            "report"                => "Report",
            "outbound"              => "Outbound",
        );
    
    ?>
    
    
     $name): ?>
                 $name): ?>
                    

    0 讨论(0)
提交回复
热议问题