473,549 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to show only the last row of database table

3 New Member
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 2127
Dormilich
8,658 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
sorting is the responsibility of the ORDER BY clause.
Apr 11 '16 #4
doigax
3 New Member
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
2028
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 access the field from within my program. Is there something I need to refresh or do I need to recreate he Dataapdtors
3
2504
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 sqlite3 database table. Here's the context: The OMR card reader sends a stream of 69 bytes over the serial line; the last byte is a carriage...
2
4234
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 hard to just jump straight into it, but that's the best way I learn. All I need to know is how to show all the information I have on a MySQL...
2
1325
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 share 2 e.g Sales tax = 10% Use Tax = 10% Share1 = 60% Share2 = 40% So Sales tax Amt (A) = Cost1 * Share1 * Sales Tax
3
6004
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 upgrade script I wrote weeks ago, and has worked fine everywhere. After the patch from last Wednesday. "Security Update for SQL Server 2000 Service...
0
1664
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 the GridView header where I type the number of rows I want to show in insert mode. Say I type 12. 2. When I click Add, the GridView changes to insert...
2
14645
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 can I pass null value as parameter to the database stored procedure programattically using C#? Although I can check for empty column (the...
11
2569
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 coulmns and also it would insert a 0 into the third column. but when i run the query directly on the database using this sql INSERT INTO crops...
2
2060
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 DAO.Database
0
1034
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; $how_long = $_POST; $how_many = $_POST; $alien_description = $_POST;
0
7521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7959
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7810
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5369
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
764
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.