我有7条mysql记录,其中包含五个值accepted = '1'
,accepted = '0'
user_id
的两个accepted = '1'
值为(6, 5, 4, 2, 1)
,accepted = '0' is (7, 3).
的{{1}}我有一个变量{{1必须按值$uid
按值组织值(6,5,4,2,1),所以在所有链接字段中,$ uid值按顺序更改(1,2,3,4) ,5)。我试过这样的事。我需要它像这样。
(5, 4, 3, 2, 1)
代码是这样的:
<a href="readmore.php?page=<?php echo 1; ?>"> More</a>
<a href="readmore.php?page=<?php echo 2; ?>"> More</a>
<a href="readmore.php?page=<?php echo 3; ?>"> More</a>
<a href="readmore.php?page=<?php echo 4; ?>"> More</a>
<a href="readmore.php?page=<?php echo 5; ?>"> More</a>
答案 0 :(得分:0)
我在Bjoern发布的链接中找到了答案。
Mysql order by specific ID values
CREATE TABLE `new_order` (
`my_order` BIGINT(20) UNSIGNED NOT NULL,
`my_number` BIGINT(20) NOT NULL,
PRIMARY KEY (`my_order`),
UNIQUE KEY `my_number` (`my_number`)
) ENGINE=INNODB;
This table will now be used to define your own order mechanism.
Add your values in there:
my_order | my_number
---------+----------
1 | 1
2 | 5
3 | 4
4 | 3
...and then modify your SQL statement while joining this new table.
SELECT *
FROM your_table AS T1
INNER JOIN new_order AS T2 on T1.id = T2.my_number
WHERE ....whatever...
ORDER BY T2.my_order;