2016-07-21 6 views
0

Ich schreibe 2 Abfragen und die erste Abfrage funktioniert gut, aber die zweite Abfrage funktioniert nicht. Bitte, führe mich. Danke.Ich schreibe 2 Abfragen, aber die zweite Abfrage funktioniert nicht

<table class="table table-bordered table-hover"> 
    <form role="form" method="post" action="">    
    <div class="tablenav top"> 
     <div class="alignleft actions bulkactions"> 
     <label for="bulk-action-selector-top" class="screen-reader-text">Comment Action</label><select name="comment_status" id="bulk-action-selector-top"> 
      <option value="" name="">Select Option</option> 
      <option value="Approve" name="Approve">Approve</option> 
      <option value="unapprove" name="unapprove" class="hide-if-no-js">Unapprove</option> 
     </select> 
     <input type="submit" name="submit" id="doaction" class="button action" value="Apply"> 
     </div> 
     <br class="clear"> 
    </div> 
    <thead> 
     <tr> 
     <th></th> 
     <th>Id</th> 
     <th>Author</th> 
     <th>Comments</th> 
     <th>Email</th> 
     <th>Author Url</th> 
     <th>Status</th> 
     <th>Date</th> 
     <th>Post Name</th> 
     <th>Edit</th> 
     <th>Delete</th> 
     <th>Reply</th> 
     </tr> 
    </thead> 
    <tbody> 
     <?php 
     $query = "SELECT * FROM comments"; 
     global $connection; 
     $select_comments = mysqli_query($connection, $query) or die('Could not look up user information; ' . mysqli_error($connection)); 
     while ($row = mysqli_fetch_array($select_comments)) { 
     $comment_id = $row['comment_id']; 
     $comment_post_id = $row['comment_post_id']; 
     $comment_author = $row['comment_author']; 
     $comment_date = $row['comment_date']; 
     $comment_email = $row['comment_email']; 
     $comment_author_url = $row['comment_author_url']; 
     $comment_content = $row['comment_content']; 
     $comment_status = $row['comment_status']; 

     echo "<tr> 
       <td><input type='checkbox' name='check_list[]' value='$comment_id'></td> 
       <td>$comment_id</td> 
       <td>$comment_author</td> 
       <td>$comment_content</td> 
       <td>$comment_email</td> 
       <td>$comment_author_url</td> 
       <td>$comment_status</td> 
       <td>$comment_date</td> 
       </tr>"; 
     } 
     if (isset($_POST['submit'])) { 
     global $connection; 
     global $errors; 

     $comment_status = $_POST['comment_status']; 
     $check_box = isset($_POST['check_list']) ? $_POST['check_list'] : ''; 

     //  error messages 
     $missingcheckbox = "<p><stong>Recored box not checked.Please check the checkbox.</strong></p>"; 

     //  for name feild 
     if (!$check_box) { 
      $errors .= $missingcheckbox; 
     } 

     if ($errors) { 
      $resultMessage = '<div class="alert alert-danger">' . $errors . '</div>'; 
      echo $resultMessage; 
     } else { 
      for ($i = 0; $i < count($_POST['check_list']); $i++) { 
      $id = $_POST['check_list'][$i]; 
      if ($comment_status == 'Approve') { 
       $query = "UPDATE comments SET comment_status = 'approved' WHERE comment_id = $id"; 
      } elseif ($comment_status == 'Unapprove') { 
       $query = "UPDATE comments SET comment_status = 'unapproved' WHERE comment_id = $id"; 
      } 

      if ($approve_comments = mysqli_multi_query($connection, $query)) { 

      // header ("location: comments.php"); 
      // exit; 

       $resultMessage = '<div class="alert alert-success">Data has been successfully Updated.<a href="../includes/comments.php"><img src="../../assets/img/refresh.png" alt="Edit Client" title="Refresh" style="width:30px; height:30px; border:0;"></a></div>'; 
       echo $resultMessage; 
      } else { 
       $resultMessage = '<div class="alert alert-warning">ERROR: Unable to excecute:' . $query . ' . ' . mysqli_error($connection) . '</div>'; 
       echo $resultMessage; 
      } 
      } 
     } 
     } 
     ?> 
    </tbody> 
</table> 

Die erste Abfrage funktioniert gut, aber zweite Abfrage ist nicht working.I haben Problem in diesem Code unten: -

if($comment_status =='Approve'){  
$query = "UPDATE comments SET comment_status = 'approved' WHERE comment_id = $id"; 

    }elseif($comment_status =='Unapprove'){  
$query = "UPDATE comments SET comment_status = 'unapproved' WHERE comment_id = $id"; 
    } 
+0

Was funktioniert nicht? Geht es in das Else? – epascarello

Antwort

4

Fall wichtig, wenn zwei Strings vergleicht die gleiche

<option value="unapprove" 
       ^^^ 
sein

und

elseif($comment_status =='Unapprove'){ 
         ^^^ 
0

$ id ist eine Variable und Sie setzen sie als String. Beispiel:

<?php 
    $a = "Hello "; 
    $b = $a . "World!"; // "Hello World!" 

    $a = "Hello "; 
    $a .= "World!";  // "Hello World!" 
?> 

Sie müssen das gleiche tun.

Verwandte Themen