Jump to content

[SOLVED] get user name with latest timestamp


supergrame

Recommended Posts

i have a table users and a field username and a field time

 

all i want to do is get the last person entered into the database via the time and put it in a variable so i can echo it out.

 

i have been looking through some sample code but it just doesn't seem to work.

Link to comment
Share on other sites

this is what i used

$sql = "SELECT username FROM users ORDER BY time LIMIT 1";

$result=mysql_query($sql) or die(mysql_error());

echo $result;

 

 

this is what the output was not the username.

Resource id #10

 

is that becuase of this mysql_query($sql)

Link to comment
Share on other sites

You need to fetch the array of results.

$result = @mysql_query ($query); // Run the query.

if (mysql_num_rows($result) == 1) { // Valid user ID, show the form.

	// Get the user's information.
	$row = mysql_fetch_array ($result, MYSQL_NUM);

	// Create the form.
	echo '<h2>Delete a User</h2>
<form action="delete_user.php" method="post">
<h3>Name: ' . $row[0] . '</h3>

Link to comment
Share on other sites

that made little scene to me, sorry i am just a newbie,

 

maybe id there is an easy way for me to understand.

 

all i want to do is is fetch the latest date/time from time field and relate that to the username and then echo out that user name.

Link to comment
Share on other sites

this is what i use

<?php

 

$query  = "SELECT username FROM users ORDER BY time LIMIT 1";

echo $result['username'];

?>

 

this is my error

 

Notice: Undefined variable: result in C:\wamp\www\public\includes\news.php on line 4

 

['username'] relate to the field username?

Link to comment
Share on other sites

$query= mysql_query("SELECT * FROM users ORDER BY time LIMIT 1") or DIE(mysql_error());
                while($r=mysql_fetch_array($query))
	{
                $username = $r["username"];
                }

echo "$username";

 

Tell me what happens when you use that.

Link to comment
Share on other sites

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.