如何反向显示表数据? (PHP) [英] How to display table data in reverse? (php)

查看:118
本文介绍了如何反向显示表数据? (PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的代码来显示图像。我创建了包含4列(ID,位置,捕获,等同)的表,并在其中插入了18条记录。我的问题是:如何以反向模式显示表中的所有记录?我需要首先显示最后一个条目,最后显示第一个条目。

I have simple code for displaying images. I created table with 4 columns (ID, location, capture, equence) and inserted there 18 records. My question is: how to display all records from table in reverse mode? I need to make that the last entry will be displayed first, and the first entry displayed last.

我需要什么:18-1
我现在拥有什么:1-18

What I need: 18-1 What I have now: 1-18

我正在寻找简单的代码来做到这一点,但是根本没有工作。所以如果有人帮我解决这个问题,我将非常感激。

I was searching for simple codes to do that, but notwing worked at all. So i'd be very grateful if someone will help me to solve that problem.

继承我的显示脚本的基本代码:

Heres the basic code of my display script:

<?php

mysql_connect("localhost", "***", "***") or die(mysql_error());
mysql_select_db("martinidb1337") or die(mysql_error());

$result = mysql_query("SELECT * FROM klpgalerija") or die(mysql_error()); while($row = mysql_fetch_array( $result )) {

    echo '<p><img src="'.$row['location'].'"></p>';
}






推荐答案

你必须使用mysql ORDER BY 条款,

You have to use mysql ORDER BY clause for that,

SELECT * FROM klpgalerija ORDER BY id DESC

注意 请不要在新代码中使用 mysql _ * 函数 。他们不再维护并正式弃用

Note : Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated.

因此,请使用 PDO MySQLi (IMO PDO是可行的方式)

So use either PDO or MySQLi (IMO PDO is way to go)

这篇关于如何反向显示表数据? (PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆