Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2. $dbhost = 'localhost';
  3. $dbuser = 'root';
  4. $dbpass = '';
  5. $selection = "ORDER BY id ASC";
  6. $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  7. if(! $conn )
  8. {
  9. die('Could not connect: ' . mysql_error());
  10. }
  11.  
  12. $selection=isset($_GET['sort']) ? $_GET['sort'] : "";
  13. if($selection == "1"){$selection="ORDER BY id DESC";} // if selection equals to 1 then sort by newest
  14. else if($selection == "2"){$selection="ORDER BY id ASC";} // else if selection equals to 2 then sort by oldest
  15.  
  16.  
  17. $sql="SELECT id, threadName, message FROM threads "; // don't forget space the end of sql
  18. $sql.=$selection;
  19.  
  20. mysql_select_db('threads');
  21. $retval = mysql_query( $sql, $conn );
  22. if(! $retval )
  23. {
  24. die('Could not get data: ' . mysql_error());
  25. }
  26. while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
  27. {
  28. $id = $row['id'];
  29. $threadName = $row['threadName'];
  30. $message = $row['message'];
  31. echo "<div class='boxed'><center>".$threadName."<br>".$message."</center></div>";
  32. }
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement