Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dbhost = 'localhost';
- $dbuser = 'root';
- $dbpass = '';
- $selection = "ORDER BY id ASC";
- $conn = mysql_connect($dbhost, $dbuser, $dbpass);
- if(! $conn )
- {
- die('Could not connect: ' . mysql_error());
- }
- $selection=isset($_GET['sort']) ? $_GET['sort'] : "";
- if($selection == "1"){$selection="ORDER BY id DESC";} // if selection equals to 1 then sort by newest
- else if($selection == "2"){$selection="ORDER BY id ASC";} // else if selection equals to 2 then sort by oldest
- $sql="SELECT id, threadName, message FROM threads "; // don't forget space the end of sql
- $sql.=$selection;
- mysql_select_db('threads');
- $retval = mysql_query( $sql, $conn );
- if(! $retval )
- {
- die('Could not get data: ' . mysql_error());
- }
- while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
- {
- $id = $row['id'];
- $threadName = $row['threadName'];
- $message = $row['message'];
- echo "<div class='boxed'><center>".$threadName."<br>".$message."</center></div>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement