php/mysql question, retrieving information
I have a question, pretty new at PHP and MySql
but was curious is it possible to display only the most recent column to a开发者_如何学Go table, from a database?
I know it is possible to display a list of all information, or if you have just one column of information in your table to display that using the
Here is my code for my basic script (just loads 1 column of information) I would like it to only print out the recent column i added to the table
$con = mysql_connect ("localhost","username","password");
if (!$con)
{
die ('Could not connect:' . mysql_error()0;
}
mysql_select_db("db_name", $con);
$result = mysql_query(Select column FROM table");
while($row = mysql_fetch_array($result))
{
echo $row['column'];
}
mysql_close($con);
* keep in mind, im not looking for someone to shoot me my code with it completed, though it would be handy, however just giving me the options of what I have to do, or what the script is called would be plentiful enough for my research, thanks!
Assuming you are talking about the most recent row there are several options, but if you have an auto-increment ID value (a lot of my tables do...), you can simply:
SELECT * FROM table ORDER BY `id` DESC LIMIT 1
You'd have to add a timestamp column to your table, ORDER BY the timestamp and LIMIT the result set.
if you want to fetch the most recent data from only 1 column then I believe the following code will help (id should be in order. it would be good if auto increment is set):
SELECT column FROM table ORDER BY `id` DESC LIMIT 1
精彩评论