Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2. $db_host="localhost";
  3. $db_user="root";
  4. $db_password="";
  5. $db_name="dentaldb";
  6.  
  7. //connect to db
  8. $db = new mysqli($db_host,$db_user, $db_password, $db_name);
  9. if ($db->connect_errno) {
  10. //if the connection to the db failed
  11. echo "Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error;
  12. }
  13.  
  14.  
  15. $query="SELECT * FROM chat ORDER BY id DESC";
  16. //execute query
  17. if ($db->real_query($query)) {
  18. //If the query was successful
  19. $res = $db->use_result();
  20.  
  21. while ($row = $res->fetch_assoc()) {
  22.  
  23. $userid=$row["user_id"];
  24.  
  25. $query1 = $db->query("SELECT * FROM members WHERE id = ".$userid);
  26. $row1 = $query1->fetch_assoc();
  27.  
  28. $username=$row1["name"];
  29. $text=$row["text"];
  30. $time=date('G:i', strtotime($row["time"])); //outputs date as # #Hour#:#Minute#
  31.  
  32. echo "<p>$time | $username: $text</p>\n";
  33. }
  34. }else{
  35. //If the query was NOT successful
  36. echo "An error occured";
  37. echo $db->errno;
  38. }
  39.  
  40. $db->close();
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement