jeudi 16 juillet 2015

how to apply condition on select distinct query

im making a web page in php of creating random numbers on the screen from 0 to 99. and im storing it in database and then fetching it by slect distinct query because i dont wanna repeat the numbers.. The problem is that i wanna echo something or show a alert box when no distinct number is selected. and i cant figure it out.. Please someone help me..

<?php
$con=mysqli_connect('localhost','root','','bingo');
   if(isset($_POST['btn1'])){
        $sqli_del="DELETE FROM `numbers`";
       $que=mysqli_query($con, $sqli_del);
      if($que){
      echo "ALL NUMBERS ARE DELETED!!!!";
      }
     else{
      echo 'There is somethin wrong with the query...';
     }

     }
   if(isset($_POST['btn'])){
  $var=mt_rand(0,99);

    $sql="INSERT INTO `numbers`(`number`) VALUES ('$var')";
     $query=mysqli_query($con, $sql);

    $sqli="SELECT DISTINCT number FROM `numbers`";
     $res=mysqli_query($con, $sqli);


     }


    ?>

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     
    "http://ift.tt/kkyg93">
     <html xmlns="http://ift.tt/lH0Osb">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <title>Bingo</title>
      <style>
     .main{margin:0 auto;}
     .form{  margin: auto;
       width: 71%;}
    .form input{width:90px;
      height:50px;}
         .spin{background-color:green; color:white; border-radius:10px;font-
       weight:bold;}
     .del{background-color:red; color:white; border-radius:10px;font- 
    weight:bold;}
       .number{ 
    width: 110px;
       height: 107px;
      font-size: 98px;
       color: blue;
        background-color: black;
       padding-left: 22px;
   margin-left: 25px;}
   .left{float:left;}
   .right{float:left;padding:250px;}
  a{text-decoration:none;}
    .back{text-align:left !important;float:left;color:blue;}
     .button{float:left;padding-top:20px;}
     </style>
   </head>

  <body>
    <div class="main">
     <div class="form">
    <form method="POST" action="">
    <div class="left">
    <?php if(!empty($res)) {?>
     <div class="back">
    <?php
      $count=mysqli_num_rows($res);
     echo "(".$count.' '. 'numbers are printed..'.")"."<br>";

        while($row=mysqli_fetch_assoc($res)){
     $num=$row['number'];

      echo $num."<br>";}


     ?>
    </div>
    <?php } ?>
    </div>

     <div class="right">
     <?php if(!empty($num)) {?>

     <div class="number"> 
     <?php 
       echo $num ."<br>";?>
       </div>
     <?php } ?>
         <div class="button">
      <a href=""><input class="spin" type="submit" name="btn" value="Spin">           
      </a>
     <a href=""><input class="del" type="submit" name="btn1" value="Delete         
    All"></a>
     </div>
      </div>
    </form>
    </div>

    </div>
  </body>
    </html>




Aucun commentaire:

Enregistrer un commentaire