Jump to content

Ascending and Decending - ARGH!


mikeybk9

Recommended Posts

Howdy... I only know basic PHP and I'm working with a database for the first time now.

 

I've made a page that can be updated using a form and i've got it all working perfect EXCEPT that I want the new entries to appear at the TOP, not at the BOTTOM.

 

 

I've used phpMyAdmin to set up the table and was wondering if there is a function in there?

 

Cheers

 

Mikey

Link to comment
https://forums.phpfreaks.com/topic/98111-ascending-and-decending-argh/
Share on other sites

I assume this is the bit of the code that needs the "order by" in it...

 

<? 
echo "<div align=center><img src=/images/".$rows['thephoto'] ." width=400> <div /><br>"; 
echo "<div align=left>".$rows['thetext']."<div />"; // <--- THIS IS THE BIT THAT I WANT ORDERED DIFFERENTLY
?>

 

After doing my own research, this bit might be usefull too...

 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>

Found an article here:

 

It explained what I needed to know about "ORDER BY"...

 

Original code...

$sql="SELECT * FROM $tbl_name";

 

New code that does the job... (Note: I made a new field in my table called "id" which auto incraments to help)

$sql="SELECT * FROM $tbl_name ORDER BY id DESC";

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.