Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Wed Jul 28, 2004 12:29 am
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 ***
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Wed Jul 28, 2004 12:30 am
Code: Select all
SELECT * FROM table ORDER BY date_joined_field LIMIT 1
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Wed Jul 28, 2004 1:50 am
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
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Wed Jul 28, 2004 1:55 am
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'];
?>
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Wed Jul 28, 2004 8:55 am
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
jtc970
Forum Commoner
Posts: 38 Joined: Sun Jan 18, 2004 11:49 pm
Post
by jtc970 » Wed Jul 28, 2004 9:32 am
Code: Select all
$sql = "SELECT * FROM users ORDER BY -reg_date LIMIT 1";
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jul 28, 2004 10:59 am
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Wed Jul 28, 2004 6:50 pm
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
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Wed Jul 28, 2004 7:35 pm
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?'
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Wed Jul 28, 2004 7:38 pm
Yeah, its certainly the way i would always do it. Sorry that i missed the DESC off my first post btw
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Thu Jul 29, 2004 3:29 am
well, I said it's not perfect only because it doesn't output a true reading, but it is close enough for me..