mercredi 25 octobre 2017

Better way of filtering multiple checkboxes php

I am trying to make a php , mysql simple check box filter. enter image description here

So there are 3 sections of checkboxes and user need to select atleast any one of each for result to display.

My code

if(isset($_POST['cse'])){ $cse=1;} else $cse=0;
    if(isset($_POST['ee'])){ $ee=2;} else $ee=0;
    if(isset($_POST['me'])){ $me=3;} else $me=0;

    if(isset($_POST['btech'])){ $btech=1;} else $btech=0;
    if(isset($_POST['mtech'])){ $mtech=2;} else $mtech=0;
    if(isset($_POST['phd'])){ $phd=3;} else $phd=0;

    if(isset($_POST['y2014'])){ $y2014=14;} else $y2014=0;
    if(isset($_POST['y2015'])){ $y2015=15;} else $y2015=0;
    if(isset($_POST['y2016'])){ $y2016=16;} else $y2016=0;
    if(isset($_POST['y2017'])){ $y2017=17;} else $y2017=0;
    if(isset($_POST['cg'])){$cg=test_input($_POST['cg']);} else $cg=0;



if($cse!=0 && $btech!=0 && $y2014!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$btech AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}}


if($cse!=0 && $btech!=0 && $y2015!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$btech AND year=$y2015 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($cse!=0 && $btech!=0 && $y2016!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$btech AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($cse!=0 && $btech!=0 && $y2017!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$btech AND year=$y2017 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}


if($cse!=0 && $mtech!=0 && $y2014!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$mtech AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}


if($cse!=0 && $mtech!=0 && $y2015!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$mtech AND year=$y2015 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($cse!=0 && $mtech!=0 && $y2016!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$mtech AND year=$y2016 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($cse!=0 && $mtech!=0 && $y2017!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$mtech AND year=$y2017 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($cse!=0 && $phd!=0 && $y2014!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$phd AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($cse!=0 && $phd!=0 && $y2015!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$phd AND year=$y2015 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($cse!=0 && $phd!=0 && $y2016!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$phd AND year=$y2016 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($cse!=0 && $phd!=0 && $y2017!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$cse AND batch=$phd AND year=$y2017 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}




if($me!=0 && $btech!=0 && $y2014!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$btech AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($me!=0 && $btech!=0 && $y2015!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$btech AND year=$y2015 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($me!=0 && $btech!=0 && $y2016!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$btech AND year=$y2016 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($me!=0 && $btech!=0 && $y2017!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$btech AND year=$y2017 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}


if($me!=0 && $mtech!=0 && $y2014!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$mtech AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}


if($me!=0 && $mtech!=0 && $y2015!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$mtech AND year=$y2015 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($me!=0 && $mtech!=0 && $y2016!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$mtech AND year=$y2016 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($me!=0 && $mtech!=0 && $y2017!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$mtech AND year=$y2017 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($me!=0 && $phd!=0 && $y2014!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$phd AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($me!=0 && $phd!=0 && $y2015!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$phd AND year=$y2015 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($me!=0 && $phd!=0 && $y2016!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$phd AND year=$y2016 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($me!=0 && $phd!=0 && $y2017!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$me AND batch=$phd AND year=$y2017 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($ee!=0 && $btech!=0 && $y2014!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$btech AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($ee!=0 && $btech!=0 && $y2015!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$btech AND year=$y2015 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($ee!=0 && $btech!=0 && $y2016!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$btech AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($ee!=0 && $btech!=0 && $y2017!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$btech AND year=$y2017 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}


if($ee!=0 && $mtech!=0 && $y2014!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$mtech AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}


if($ee!=0 && $mtech!=0 && $y2015!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$mtech AND year=$y2015 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($ee!=0 && $mtech!=0 && $y2016!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$mtech AND year=$y2016 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($ee!=0 && $mtech!=0 && $y2017!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$mtech AND year=$y2017 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}



if($ee!=0 && $phd!=0 && $y2014!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$phd AND year=$y2014 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($ee!=0 && $phd!=0 && $y2015!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$phd AND year=$y2015 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($ee!=0 && $phd!=0 && $y2016!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$phd AND year=$y2016 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

if($ee!=0 && $phd!=0 && $y2017!=0){
$sql = "SELECT * FROM tnp_users WHERE branch=$ee AND batch=$phd AND year=$y2017 AND cgpa>=$cg";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $entry_no=$row['entry_no'];
        echo "<tr><td> " . $row["entry_no"]."</td><td contenteditable='true' onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",0)'>" . $row["cgpa"]."</td><td contenteditable='true'  onBlur='saveToDatabase(this.innerHTML,".$row["user_id"].",1)' >".$row["strikes"]."</td></tr>";
    }

}
}

Now i manually made all the cases what the user can do , in my approach there is a lot of repetition and also if the no of checkboxes increase it will be very difficult to count all the cases




Aucun commentaire:

Enregistrer un commentaire