TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-24-2012, 03:51 PM   #1 (permalink)
The Wanderer
 
Timms's Avatar
 
Join Date: May 2012
Posts: 6
Thanks: 2
Timms is on a distinguished road
Default Re-order display of data-base

I have a table on my site of names and comments that is pulled from a sql data-base. Works perfect you can add comments aswell.

How would i go about displaying it as the last comment that was posted to be on top rather than at the bottom?

my current code for displaying the table is:

PHP Code:
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)){
?>
<table width="100%" border="0">
<tr>
<td><table width="100%" border="0" bordercolor="#FF0000">
<tr>
<td class="commentsname"><? echo $rows['name']; ?>:</td>
<td class="commentstxt"><? echo $rows['comment']; ?></td>
</tr>
</table></td>
</tr>
</table>
which displays perfect only i want the latest comment on top instead of pusshed down to the bottom help appriciated
Timms is offline  
Reply With Quote
Old 05-24-2012, 05:40 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

does your table only has the fields name and comment? you would need an extra field that would hold the date and time when the comment was created then you can order them. For example lets say the field is named created, the sql query would be something like this

sql Code:
SELECT * FROM $tbl_name ORDER BY `created` DESC
the DESC is for descending order, the other option is ASC for ascending order.

I hope this helps.
tony is offline  
Reply With Quote
The Following User Says Thank You to tony For This Useful Post:
Timms (05-24-2012)
Old 05-24-2012, 06:53 PM   #3 (permalink)
The Wanderer
 
Timms's Avatar
 
Join Date: May 2012
Posts: 6
Thanks: 2
Timms is on a distinguished road
Default

ye it does actually have a date and time but i did try that with date and time but think i got it wrong. Either way i just did the same as what you did only witht he ID from the db which in my eyes is ideal anyway unless thats something that should not be done never the less it seems to work :D thanks for that :D
Timms is offline  
Reply With Quote
Old 05-25-2012, 12:43 PM   #4 (permalink)
The Wanderer
 
Timms's Avatar
 
Join Date: May 2012
Posts: 6
Thanks: 2
Timms is on a distinguished road
Default

ok now i have another problem...

it does order correctly to a certain degree

i have changed the order to a different field now which is an alt date which is put in to a field and subbmited via a form

trouble is the dates get mixed up.

if i have 1,5,2012 in one record
13,5,2012 in the second record
and 1,6,2012 in the third record

1,6,2012 will display as the second record on the table i have which is not what i need becase 1,6,2012 is after 13,5,2012

if you refer to my screenshot for a better description
http://www.chulse.co.uk/date-error.png

you can see friday `1, june 2012 is the 2nd row down which should be the last row. It is not ordering from this date it is ordering from a hidden date which is the same just in a different format. dateFormat: 'd-m-y',

how would i go about getting this in the right order?

Thanks
Timms is offline  
Reply With Quote
Old 03-30-2013, 07:54 AM   #5 (permalink)
The Acquainted
 
Join Date: Mar 2013
Posts: 131
Thanks: 1
caiyanfang is on a distinguished road
Default Nike Free 3.0 V2 : Nike Free Run Shoes

Don't worry Additionally there is a as Nike encompasses a line of green shoes for you guessed it-your camera. cheap air jordan shoes In fact however , there is more options easily to get lime green Nike shoes for ladies though all tailored specifically to suit running. Choose shoes involving Nike Air Max Line and also LunarGlide and and the wonderful Kukini Fee wrinkles. You can find full green shoes or see black shoes with green cheap air jordans swoosh and trimmings. Run and train in comfort and style with Nike shoes for women.
caiyanfang is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Injection and mysql_real_escape_string Durux General 61 01-29-2013 12:20 PM
PHP Beginner Guide #1 Hershey Absolute Beginners 1 11-07-2011 10:42 PM
How do i Display XML data with Namespace using XSLT Help mobimad General 6 09-27-2010 06:44 PM
Venerable methods and the applications they are commonly trusted in. Village Idiot Tips & Tricks 7 11-06-2008 07:36 AM
Tips: PHP security Village Idiot Tips & Tricks 22 11-23-2007 11:17 PM


All times are GMT. The time now is 05:23 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design