2017-02-08 14 views
0

こんにちは、idがdbの最大IDを上回っている場合、URL idを変更するにはどうすればよいですか?URL IDを変更するにはどうすればよいですか?

私はデータベースからIDを取得し、別のURLクエリとしてIDを持つ新しいページのデータを人々が読めるようにするために、より多くのボタンを使用しますか?

--The私はデシベルで4つのニュースがある場合ということにあなたが書いた場合ていることを確認するにはどうすればよい本当の問題 など、ブラウザが実行するかに戻って行くことはありませんブラウザで newsTest.php?ID = 5最大ページ?

//read more button 
<a href="newsTest.php?id=<?php echo $id ?>">Læs mere</a> 


<?php 
    include_once 'includes/db.php'; 
      $sql1 = "SELECT COUNT(id) AS total FROM rock_news "; 
      $result1 = $dbCon->query($sql1); 
      $row1 = $result1->fetch_assoc(); 

      $total_pages = $row1["total"]; 
      $thisVar = $_GET['id']; 

      if($total_pages >= $thisVar){ 
       echo "alt er godt"; 


    if(isset($_GET['id']) && !empty($_GET['id'])){ 

     $id = $_GET['id']; 

     // mod sqlinjection 
     $id = $dbCon->real_escape_string($id); 

     $sql = " SELECT id, heading, subheading, description, created, author FROM rock_news WHERE id = " . $id ; 

     $result = $dbCon->query($sql); 

     if ($result->num_rows > 0) { 
      $row = $result->fetch_object(); 
       $id = $row->id; 
       $heading = utf8_encode($row->heading); 
       $subheading = utf8_encode($row->subheading); 
       $description = utf8_encode($row->description); 
       $created = $row->created; 
       $author = utf8_encode($row->author); 

      $output .= $id . "<br>" . $heading . "<br>" . $description; 




     }; 
     // udskriv output til bruger 
     echo $output; 
    }; 
} else { 
    $_GET['id'] = $total_pages ; 
      echo "nothing"; 
} 
?> 

私はTOTAL_PAGESが、その後ショーTOTAL_PAGES IDを示しIDよりも小さい場合

答えて

0

チェックをPHPに非常に新しいです。

<?php 
     include_once 'includes/db.php'; 
       $sql1 = "SELECT COUNT(id) AS total FROM rock_news "; 
       $result1 = $dbCon->query($sql1); 
       $row1 = $result1->fetch_assoc(); 




     if(isset($_GET['id']) && !empty($_GET['id'])){ 
      $total_pages = $row1["total"]; 
      $thisVar = $_GET['id']; 

       if($total_pages < $thisVar){ 
        $thisVar=$total_pages 
      $id = $thisVar; 

      // mod sqlinjection 
      $id = $dbCon->real_escape_string($id); 

      $sql = " SELECT id, heading, subheading, description, created, author FROM rock_news WHERE id = " . $id ; 
関連する問題