-1

我需要我的 php 从 Opposite 的表中选择一些数据

就像我有桌子一样,他有这样的身份

1 2 3 5

我需要这样展示

5 3 2 1 通过选择查询

这是我的代码(不完整)

在 tech.php 中

<?PHP require_once('post_technology.php'); ?>
<?PHP $posts= post_technology::find_all();  ?>    
<?PHP foreach($posts as $post): ?>
<!--start post -->
<div class="item">
<h2><a href="technology_post.php?id=<?PHP echo $post->id; ?>"><?PHP echo $post->post_name; ?></a></h2>
<div class="info">
<span class="date"><?PHP echo $post->post_time; ?></span>
<span class="author">by <?PHP echo $post->post_user; ?></span>
<a href="technology_post.php?id=<?PHP echo $post->id; ?>" class="comments">comments</a>
</div>
<a href="technology_post.php?id=<?PHP echo $post->id; ?>"><img src="<?PHP if($post->post_photo == "post_img/"){echo ".\images\no-photo.jpg";}else{ echo $post->post_photo; } ?>" alt="" width="850" height="250" class="image" /></a>
<p><?PHP echo $post->post_e5tsar; ?></p>
<p class="last"><a href="technology_post.php?id=<?PHP echo $post->id; ?>" class="more-link"><span>Read more</span></a></p>
<!-- END .item -->
</div>
<!-- end al post -->
<?php endforeach ; ?>

post_technology.php:

class post_technology {
    protected static $table_name="post_technology";
    protected static $db_fields=array('id', 'post_name', 'post_user', 'post_time', 'post_photo', 'post_e5tsar', 'post_full', 'post_table');
    public $id;
    public $post_name;
    public $post_user;
    public $post_time;
    public $post_photo;
    public $post_e5tsar;
    public $post_full;
    public $post_table;
    public $errors=array();


  public static function find_by_id($id=0) {
    $result_array = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE id={$id}  LIMIT 1");
        return !empty($result_array) ? array_shift($result_array) : false;
  }

  public static function find_by_sql($sql="") {
    global $database;
    $result_set = $database->query($sql);
    $object_array = array();
    while ($row = $database->fetch_array($result_set)) {
      $object_array[] = self::instantiate($row);
    }
    return $object_array;
  }

这是我在 tec.php 中发布的代码 跳到它首先发布新帖子

4

1 回答 1

1
SELECT * FROM table ORDER BY id DESC
于 2012-07-12T20:45:07.983 回答