FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Finding the newest entry in a mysql database?





Diablosblizz
Hey, im starting to learn php with mysql Smile. I've been able to connect, and show how many rows in the database (thats a start). Now, im having some problems.

I would like to show the newest entry of the mysql database, from one speicif "column", i think thats what it is. I don't want it to display everything (cause that will leak out the password), all I want is it to show a part of the column called "username", and display its name that is already there.

For example:

Newest member: MemberName

So far, I have this code:

Code:
<?php
mysql_connect("localhost","diablosb_users","password");
mysql_select_db(diablosb_users) or die(mysql_error()); 

mysql_info()
?>


I thought mysql_info returned information about the last query, and I got that from W3Schools.

Please help a mysql / php noob Smile.


Thanks.
mathiaus
You haven't done any queries in that code though using that connection.

You want to select 1 row from the database, taking that row's username and most likely id as well to make a link.
If you have an auto_incrementing ID field just use a query like the below;
Code:
SELECT `id`, `username` FROM `users` ORDER BY `id` DESC LIMIT 1

As you can see from here, we take the id and username from the database which is ordered descending by the id field, limit 1 means we only take the first row Smile
Diablosblizz
Quote:
Parse error: syntax error, unexpected '`' in /home/diablosb/domains/hotelmario.info/public_html/members/test.php on line 5


????
TheGustav
Diablosblizz wrote:
Quote:
Parse error: syntax error, unexpected '`' in /home/diablosb/domains/hotelmario.info/public_html/members/test.php on line 5


????


Try removing the `?
Diablosblizz
Well, considering theres.. erm about 5 which one would I?

Please read the code before you post.
TheGustav
How about all 5? Smile
DanielXP
Code:
<?php
include("config.php");
$new = mysql_fetch_array(mysql_query("SELECT * FROM `members` ORDER BY `id` DESC LIMIT 0, 1"));
echo "Newest User: " . $new[username];
?>


Should work Wink
mathiaus
Quote:
Parse error: syntax error, unexpected '`' in /home/diablosb/domains/hotelmario.info/public_html/members/test.php on line 5

What exactly have you got? (code, line 5)
Diablosblizz
DanielXP - Works perfectly! Heh, guess you knew I was using your member system xD.

Im gunna post that on your site if thats okay?
Related topics
Cron Job to Backup MySQL Database
Mysql database problem
PHPBB MYSQL Database Question.
MySQL database for a forum
Mysql database size?
Connect to MySql database
[MySQL database] Password and username
insert data to mySQL database problem
MySQL Database!?
Delete data from MySQL database problem!!
MySQL database
Changing entries in MySQL database
Optimizing a mySQL database
Is there a better way to restore mysql database?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.