Page 1 of 1

echo the very last row in one column SQL

Posted: Wed Jul 28, 2004 12:29 am
by fresh
Hey,

was wondering how I would echo to my page the very last row - field of my reg date column... I would like to echo the date and their username, but only the last entry, since that would represent the newest member... thanks :)




edited by : Infolock
*** Moved to database section ***

Posted: Wed Jul 28, 2004 12:30 am
by kettle_drum

Code: Select all

SELECT * FROM table ORDER BY date_joined_field LIMIT 1

hmm

Posted: Wed Jul 28, 2004 1:50 am
by fresh
not working, here's my code:

Code: Select all

<?php
$dat = "SELECT * FROM users ORDER BY reg_date LIMIT 1";
$datum = mysql_query($dat);

echo "".$datum."";

?>
it isn't echoing anything at the moment... thanks :)

Posted: Wed Jul 28, 2004 1:55 am
by d3ad1ysp0rk
It should be echoing "Resource ID x" or something along those lines..
Also, if all your echoing is a variable, theres no need to use "".$var."".

Try this (i'm assuming your column names are username and date):

Code: Select all

<?php
$sql = "SELECT * FROM users ORDER BY reg_date LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo "Date: " . $row['date'] . "<br />";
echo "Username: " . $row['username'];
?>

hey

Posted: Wed Jul 28, 2004 8:55 am
by fresh
thanks alot for that script, it has actually been the closest to success that I have had with this feature I have been trying to build... basically it is the newest member feature, which takes the very last entry and displays when they regisered and what their name is.. however, this script takes from the top, how would I take from the bottom, thanks :)

Posted: Wed Jul 28, 2004 9:32 am
by jtc970

Code: Select all

$sql = "SELECT * FROM users ORDER BY -reg_date LIMIT 1";

Posted: Wed Jul 28, 2004 10:59 am
by feyd
uh..

Code: Select all

ORDER BY reg_date DESC

alright

Posted: Wed Jul 28, 2004 6:50 pm
by fresh
thanks alot guys, it started working now, it's not perfect, but it's good enough for me, so thanks again, I appreciate your help :)

Posted: Wed Jul 28, 2004 7:35 pm
by tim
lol whats not perfect about it?

Doing it that way is fast, simple, and dont require alot of memory.

what more/ess to make it 'perfect?'

:wink:

Posted: Wed Jul 28, 2004 7:38 pm
by kettle_drum
Yeah, its certainly the way i would always do it. Sorry that i missed the DESC off my first post btw :P

Posted: Thu Jul 29, 2004 3:29 am
by fresh
well, I said it's not perfect only because it doesn't output a true reading, but it is close enough for me.. ;)