Jump to content

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";

 

 

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.