Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display last row in database

Posted on 2010-09-02
3
Medium Priority
?
415 Views
Last Modified: 2013-12-13
How do I display the last value of the last row in a database?

mysql_select_db($database_conn_elements, $conn_elements);
$query_rs_forum_thread_messages = "SELECT * FROM forum_thread_messages WHERE forum_thread_id = " . $row_rs_forum_thread['id'];
$rs_forum_thread_messages = mysql_query($query_rs_forum_thread_messages, $conn_elements) or die(mysql_error());
$row_rs_forum_thread_messages = mysql_fetch_assoc($rs_forum_thread_messages);
$totalRows_rs_forum_thread_messages = mysql_num_rows($rs_forum_thread_messages);


i.e. when I print the below I only want to see the message column of the last row?

echo $row_rs_forum_thread_messages['message'];

0
Comment
Question by:petewinter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 19

Accepted Solution

by:
Bardobrave earned 1000 total points
ID: 33586395
Order your query descending by the current field (as you have not defined an order by clause it will be probably ordering by query's first field) and get the first row.
0
 
LVL 2

Assisted Solution

by:Maverickerko
Maverickerko earned 1000 total points
ID: 33586417
you need some uniqe identificator as autoincremnted ID in table then you order table by this id descending and then you just return first row 


mysql_select_db($database_conn_elements, $conn_elements);

$query = "SELECT * FROM forum_thread_messages WHERE forum_thread_id = " . $row_rs_forum_thread['id']." ORDER BY id DESC LIMIT 1";
$result = mysql_query($query_rs_forum_thread_messages, $conn_elements) or die(mysql_error());

$last_message = mysql_result($result,0,"message");

$totalRows = mysql_num_rows($result);



echo $last_message;
0
 

Author Closing Comment

by:petewinter
ID: 33586495
Perfect. Many thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question