Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 如何让数据显示不重复,只显示最新数据

如何让数据显示不重复,只显示最新数据

Jun 23, 2016 pm 01:47 PM

用PHP查询数据库,但数据重复显示,如何能让数据不重复如下图:


自编号0193 06:25:35状态显示完成,但11:25:35也显示完成,如何能让同一版本号数据只显示最新的,


网页代码如下:
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 


 数据查询
 
 

 

 


 


                  
媒体版本号:
                   
选择线路
                 
                  选择状态
                 
                  
                  
                  

         
 

   if($_REQUEST['submit']!="")
 {
 $link=mysql_connect("127.0.0.1","root","12345678");   
 if(!$link) echo "没有连接成功!";   
else echo "连接成功!";   
mysql_select_db("busap", $link);          //选择数据库  

 //控制查询条件

$q = "SELECT * FROM research where banben like '%{$_REQUEST['banben']}%' AND linename like '%{$_REQUEST['xianlu']}%' AND zhuangtai like '%{$_REQUEST['zhuangtai']}%' order by busname asc";   
  
 // mysql_query("SET NAMES GB2312"); //防止乱码
$rs = mysql_query($q); //获取数据集
$assoc= mysql_num_rows($rs);///影响的行数 , 原来用了mysql_fetch_assoc
 echo "$assoc"; 

 $row=mysql_fetch_array($rs); //只需要补充回这一行. 

if(!$rs){die("Valid result!");}
 }
 ?>
 
   
     
     
     
     
     
     
     
     
     
   
           
        if($_REQUEST['submit']!="")
 {
 do { ?>

if($row[4]=="0")
{
$leixing="自动";
}
else
{
$leixing="手动";
}

if($row[8]=="fin")
{
$zhuangtai="完成";
}
else
{
$zhuangtai="未完成";
}
?>

   
     
     
     
     
     
     
     
     
     

   
   
 
线路
中心编号
线路
车辆自编号
传输方式
媒体版本
日期
时间
状态

  


回复讨论(解决方案)

加个标识列,显示过的数据,更新为1.未显示的为0,查询时,只查询标识为0的数据。

写个判断就好了,版本号相同时,取最大时间的记录

能给个详细判断代码吗,本人小白,初学者

试试

$q = "SELECT *,max(媒体版本) FROM research where banben like '%{$_REQUEST['banben']}%' AND linename like '%{$_REQUEST['xianlu']}%' AND zhuangtai like '%{$_REQUEST['zhuangtai']}%' group by 媒体版本 order by max(媒体版本) busname asc";
Copy after login

就是取媒体版本的最大值,然后显示
这不是很简单吗?
可以使用max函数.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Introduction to the Instagram API

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles