1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
| ?php
session_start();
// parametre de connexion
$host_name = "localhost";
$database = "forum_projet";
$db_user_name = "root";
$db_password = "root";
// connexion
$conn = mysqli_connect($host_name, $db_user_name, $db_password, $database);
if ($_session=['username']) {
?>
<html>
<head>
<title> home page </title>
</head>
<?php include ("header.php"); ?>
<center>
<br/>
<a href = "post.php"><button> post topic </button></a>
<br/>
<br/>
<body>
<?php
$contenu_reponse = '';
//recuperation et insertion
if (isset($_POST['repondre']))
{
$contenu_reponse = stripslashes($_POST['contenu_reponse']);
$id_sujet=$_GET['id'];
$date = date("y-m-d");
//creation de la requette
$req ="insert into reponse(id_reponse,id_sujet,contenu_reponse,createur_reponse,date) VALUES ('".$id_reponse."','".$id_sujet."','".$contenu_reponse."' , '".$_SESSION["username"]."', '".$date."')" ;
//envoie de la requette
$retour = $conn->query($req);
}
?>
<h1>Question :</h1>
<?php
if ($_GET["id"]){
$check= mysqli_query($conn," SELECT * from sujets WHERE id_sujet='".$_GET['id']."'");
if (mysqli_num_rows($check)){
while ($row=mysqli_fetch_assoc($check)){
echo"<h1> Titre du sujet : " .$row['nom_sujet']. "</h1>";
echo "<h5> Question posé par l'utilisateur ".$row['createur_sujet']."<br/> date :".$row['date']."</h5>";
echo "<br/>Question : ".$row['contenu_sujet'];
}
}else{
echo "topic not found" ;
}
}else{
header("location: index.php");
}
?>
<h1>Réponses :</h1>
<?php
if (isset($_GET['page'])) {
$currentPage = $_GET['page'] ;
}else{
$currentPage = 1 ;
}
$prevPage = $currentPage-1;
$nextPage = $currentPage+1 ;
$perPage = 5 ;
$start = ($currentPage - 1) * $perPage;
if ($_GET["id"]){
$check= mysqli_query($conn," SELECT SQL_CALC_FOUND_ROWS * from reponse WHERE id_sujet='".$_GET['id']."' limit ".$start.",".$perPage);
$rows_result = mysqli_query($conn," SELECT FOUND_ROWS() as rows ");
$rows = mysqli_fetch_assoc ($rows_result);
$totalRows = $rows['rows'];
$lastPage= ceil($totalRows / $perPage) ;
if (mysqli_num_rows($check)){
while ($row=mysqli_fetch_assoc($check)){
echo"<h4>" .$row['contenu_reponse']. "</h4>";
echo "<h5> par ".$row['createur_reponse']."<br/> date :".$row['date']."</h5>";
}
}else{
echo "topic not found" ;
}
}else{
header("location: index.php");
}
?>
<center>
<form action="" method="post">
ecrire une reponse <br><textarea cols="80" rows="15" name="contenu_reponse"></textarea><br><br>
<input type="submit" name="repondre" value="Répondre">
</form>
</center>
<?php
}else{
echo " you must be logged in";
}
?>
<div id="pages">
<?php
if ($currentPage== 1) {
echo 'Precedent' ;
}else{
echo '<a href="sujet.php?id='.$_GET['id'].'?page='.$prevPage.'">Precedent</a>' ;
}
?>
|
<?php
for ($i=1 ; $i<=$lastPage ; $i++ ){
if ($currentPage !=$i){
echo '<span class="pageNO">
<a href = "sujet.php?id='.$_GET['id'].'?page='.$i.'">'.$i.'</a></span>';
}else{
echo '<span class="activepage">'.$i.'</span>' ;
}
}
?>
|
<?php
if ($currentPage== $lastPage) {
echo 'suivant' ;
}else{
echo '<a href="sujet.php?id='.$_GET['id'].'?page='.$nextPagee.'">suivant</a>' ;
}
?>
</div>
</body>
</html> |
Partager