我需要我的PHP 从Opposite中选择表中的一些数据
就像我有tablhe那样的id
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中 跳吧先发布新帖子
答案 0 :(得分:1)
SELECT * FROM table ORDER BY id DESC