Jump to content

Order by newest


Hydrian

Recommended Posts

Im running a testing forum iv made from scratch, i want the posts to be order by newest, but there going as, order by oldest. How come this happens.

 

<?php

session_start();
error_reporting(-1);ini_set('display_errors', 1);
    $myServer = "mysql8.000webhost.com";
    $myUser = "a1761169_chat";
    $myPass = "site123";
    $myDB = "a1761169_chat";
    //Connection to the database
    $dbhandle = mysql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer");
    //Select a database to work with
    $selected = mysql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB");
$where = "";	
	if(isset($_GET['id'])){
	$id = $_GET['id'];
	$where = " WHERE id = $id";
}    



//Declare the SQL statement that will query the database
    $query = "SELECT * FROM `topics` $where ORDER BY topic_date";
    //Execute the SQL query and return records
    $result = mysql_query($query)
    or die('A error occured: ' . mysql_error());
?>
<html>
<head>
</head>

<body>
	<h2>
		My First Forum
	</h2>
		<br>
		<div style="background-color:#CCCCCC; color:#; border-radius:5px;" align=''>
			     <a href='index.php'><b>Board Index<b></a>     <a href='create_topic.php'><b>New Topic<b></a>
		</div>
		<br>
		<?php

		while ( $record = mysql_fetch_array($result) )
		{	

		echo '<div id="content" >' . '<div style="background-color:#CCCCCC; color:#; border-radius:5px;">' . '<a href="index.php">'. $record["topic_username"] .'</a>' . '     |     ' . '<a href="index.php?id=' . $record["id"] . ' ">'. $record["topic_name"] .'</a>' . '</div> ' . "<br>" . '<div style="word-wrap:break-word;div-layout:fixed; background-color:#CCCCCC; color:#; border-radius:5px;" width="500px" border="1">';
		if(isset($_GET['id'])){echo $record['topic_date']; echo "<br><br>"; echo $record['topic_input']; }
		else { echo ""; }
		echo '</div></div>';

		}
		 echo "<br><br>";
		while ( $record = mysql_fetch_array($result) )
		{	

		echo '<div id="content" >' . '<div style="background-color:#CCCCCC; color:#; border-radius:5px;">' . '<a href="index.php">'. $record["reply_username"] .'</a>' . '     |     ' . '<a href="index.php?id=' . $record["id"] . ' ">'. $record["reply_name"] .'</a>' . '</div> ' . "<br>" . '<div style="word-wrap:break-word;div-layout:fixed; background-color:#CCCCCC; color:#; border-radius:5px;" width="500px" border="1">';
		if(isset($_GET['id'])){echo $record['reply_date']; echo "<br><br>"; echo $record['reply_input']; }
		else { echo ""; }
		echo '</div></div>';

		}
		 echo "<br><br>";
		?>
</body>
</html>

 

Thats the page i want the topics to go order by descending

Link to comment
Share on other sites

As noted on IRC, not 15 minutes ago:

03:51 Jade i need to figure out how to make the newest topic on the top not the bottom

Jade than, to do the replys stuf

ChristianF Descending order by date in the SQL query.

Jade ok

<SNIP>

Jade would this work to descend by order

Jade "SELECT * FROM `topics` $where ORDER BY EventDate DESC ";

ChristianF Tried it?

03:55 Jade not yet,

ChristianF That is the best, and in fact only sure, method to find out of it works or not.

Jade yep trying now

03:57 Jade dont work :/

04:01 <- Jade has disconnected (Ping timeout: 121 seconds)

Let me re-iterate a point I made earlier, as it seems you might not have quite fully grasped what I was saying:

At this point I think you really should reconsider your choice of hobby. Either that or you need to start paying attention to stuff and actually try to learn, instead of just writing random stuff and expecting things to work without having to put forth the effort to understand why things work as they do.

In short, you need to pay attention to the things you do. Not only while you're doing them, but also before you do them. It takes a lot of effort and time to learn how become a programmer, and you must pay attention and understand every single detail.

 

Read this article, and make sure you've understood it completely: http://www.catb.org/esr/faqs/smart-questions.html#disclaimer For your own sake, if not for ours.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.