i have been trying to make a private message system by following betterphp's tutorial.
everything has worked until the part where you can delete messages. it marks the conversation as deleted in the database, but it still shows in my inbox. I have viewed the video 5 times and written the same thing as him. I know it is the query that is wrong because i have tested it in phpmyadmin. please help me.
nb: i have made a little modification. i have make a var called db because it whould not work without.
here is my code:
the fetch_conversation summery function:
function hent_samtaler(){ mysql_connect(DB_HOST, DB_USER, DB_PASS); $db= DB_NAME; $sql = "SELECT $db.`samtaler`.`samtale_id`, $db.`samtaler`.`samtale_emne`, MAX($db.`samtaler_beskeder`.`besked_dato`) AS `samtale_sidst_svaret`, MAX($db.`samtaler_beskeder`.`besked_dato`) > $db.`samtaler_medlemmer`.`samtale_sidst_set` AS `samtale_ulaest` FROM $db.`samtaler` LEFT JOIN $db.`samtaler_beskeder` ON $db.`samtaler`.`samtale_id` = $db.`samtaler_beskeder`.`samtale_id` INNER JOIN $db.`samtaler_medlemmer` ON $db.`samtaler`. `samtale_id` = $db.`samtaler_beskeder`.`samtale_id` WHERE $db.`samtaler_medlemmer`.`user_id` = {$_SESSION['user_id']} AND $db.`samtaler_medlemmer`.`samtale_slettet`= 0 GROUP BY $db.`samtaler`.`samtale_id` ORDER BY $db.`samtaler_medlemmer`.`user_id` DESC "; $resultat = mysql_query($sql); $samtaler = array(); while (($row = mysql_fetch_assoc($resultat)) !== false){ $samtaler[] = array( 'id' => $row['samtale_id'], 'emne' => $row['samtale_emne'], 'sidst_svaret' => $row['samtale_sidst_svaret'], 'ulaest' => ($row['samtale_ulaest'] == 1), ); } return $samtaler; }the inbox page:
<?php require_once("classes/Besked.php"); $errors = array(); include("elements/navbar.php"); if(isset($_GET['slet_samtale'])){ if(valider_samtale_id($_GET['slet_samtale']) === false) { $errors[] = "Ugyldig samtale id"; } if(empty($errors)){ slet_samtale($_GET['slet_samtale']); } } $samtaler = hent_samtaler(); ?> <div class="container-fluid"> <div class="row-fluid"> <div class="span3"> <?php include("elements/sidemenu.php");?> </div><!--/span--> <div class="span9"> <form method=post action=""> <div class="btn-group"> <h3>Indbakke</h3> <?php if(isset($errors)){ foreach ($errors as $error) { echo '<div class="alert alert-error">'; echo '<button type="button" class="close" data-dismiss="alert">x</button>'; echo $error; echo '</div>'; } } ?> <a href="index.php?page=ny_samtale"><button class="btn btn-success">Ny Samtale</button></a> <input type="submit" class="btn btn-danger" value="Slet"></input> <button class="btn">Inviter</button> </div> <div class="container" id="contentwrapper"> <p></p> <table class="table"> <thead> <tr> <th>Navn</th> <th>Emne</th> <th>Sidst Læst</th> <th>Slet</th> </tr> </thead> <tbody> <?php foreach($samtaler as $samtale){ ?> <tr> <td><a <?php if ($samtale['ulaest']) echo 'style="font-weight:bold;"';?> href=""><?php echo $samtale['id']; ?></a></td> <td><a <?php if ($samtale['ulaest']) echo 'style="font-weight:bold;"';?> href=""><?php echo $samtale['emne']; ?></a></td> <td><a <?php if ($samtale['ulaest']) echo 'style="font-weight:bold;"';?>> <?php echo date('d/m/Y H:i:s', $samtale['sidst_svaret']); ?></a></td> <td><a href ="index.php?page=indbakke&slet_samtale=<?php echo $samtale['id']; ?>" <?php if ($samtale['ulaest']) echo 'style="font-weight:bold;"';?>> Slet </a></td> </tr> <?php } ?> </form> </tbody> </table> </div> </div><!--/span--> </div><!--/row--> <hr> <?php include("elements/footer.php"); ?>