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.

if you can get the information from the database and pull it out as a variable you can then echo it out from there.. if your looking to convert a time stamp, if your using a unix timestamp just do something like

strtotime("g:ia", $varfortimestamp);

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)

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>

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.

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?

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.