473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to show only the last row of database table

3
Hey. I'm new to php so this question may be very easy but still... I wrote a code for connecting to a database and show all of its records but I only need the last row, can someone please tell me what to add instead of the function 'foreach'. Here's the code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $wpdb = new wpdb('username','password','database_name','localhost');
  4. $result = $wpdb->get_results( "SELECT * FROM koridorius "); 
  5. echo "TEMPERATŪRA"."  "."ŠVIESA"."<br><br>";
  6.  
  7. foreach($result as $row)
  8.  {
  9. echo $row->temperatura."  ".$row->sviesa."<br>";
  10.  }
  11.  
  12. ?>
  13.  
Apr 10 '16 #1
4 2119
Dormilich
8,658 Expert Mod 8TB
How to show only the last row of database table
there is no last row in a database table.

to get a last row, you must apply sorting and then the last row is determined by the sort condition.
Apr 11 '16 #2
doigax
3
I have dates in the datebase so that I think could be the sort condition. But how to add sorting to the code?
Apr 11 '16 #3
Dormilich
8,658 Expert Mod 8TB
sorting is the responsibility of the ORDER BY clause.
Apr 11 '16 #4
doigax
3
Thank you. The sorting works
Apr 11 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: David | last post by:
Hi, Could someone please xplain how to add a field to an existing SQL table in VB.Net I have added the field in the Server Explorer and it shows up when I reload the program but I cannot...
3
by: Rich Shepard | last post by:
I need to learn how to process a byte stream from a form reader where each pair of bytes has meaning according to lookup dictionaries, then use the values to build an array of rows inserted into a...
2
by: samui | last post by:
I'm trying to get a php page to show data from a MySQL database. But the problem that I have is I don't know where to start. I'm very new at PHP and I'm constantly told by others that it's very...
2
by: igovada | last post by:
Hi I have a table (Sql server 2000) which has 14 cost columns for each record, and now due to a new requirement, I have 2 taxes which needs to be applied on two more fields called Share1 and...
3
by: Larry Leonard | last post by:
Running MSDE 2000 SP2 on Windows XP SP3. I have a T-SQL script that is relatively simple (adding constraints, inserting rows, etc.) and short (maybe 300 lines, heavily commented). It's an...
0
by: Andy B | last post by:
I need to take an existing GridView that connects to a database and gets rows from a table and force it to show x rows in the insert mode. This is what should happen: 1. There is a TextBox in...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
11
by: sshade25 | last post by:
I am trying to insert some data into my postgresql database table using an html form and a php script. The problem here is that when the script is run, it does not insert data into the last two...
2
by: George Yar | last post by:
Re: How to show changes in open Access 2003 Table in VB I have a form to add a new record to my Access Database table. This is a code: Private Sub btnAdd_Click() Dim dbExpenses As...
0
cognition
by: cognition | last post by:
my data is not inserting in my phpmyadmin database table, please kindly help, this is my code:<?php $first_name = $_POST; $last_name = $_POST; $email = $_POST; $when_it_happened = $_POST;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.