mysqlクエリに問題があります。条件付きでmysqlの行位置を取得する方法を理解しました。私が達成したいことを説明させてください。
私はテーブルギャラリーを持っています、そしてそれはこのように見えます:
id_gallery source status post
1 img1 last 2012/12/11
5 img2 new 2013/01/01
7 img3 new 2013/01/01
10 img4 last 2012/12/11
22 img5 last 2012/12/14
30 img6 last 2012/12/15
このクエリを使用してページ内の画像(ex:test1.php)を呼び出し、次のような結果を返します。クエリは次のとおりです。
select * from gallery where status ='last' order by post DESC
これが私の結果です:
id_gallery source status post
30 img6 last 2012/12/15
22 img5 last 2012/12/14
10 img4 last 2012/12/11
1 img1 last 2012/12/11
ページギャラリーで私はこのようなクエリを作成します:
select * from gallery order by post desc
そして次のような結果を出します:
id_gallery source status post
5 img2 new 2013/01/01
7 img3 new 2013/01/01
30 img6 last 2012/12/15
22 img5 last 2012/12/14
1 img1 last 2012/12/11
10 img4 last 2012/12/11
私が達成したいのはこのようなものです:
id_gallery source status post position
5 img2 new 2013/01/01 1
7 img3 new 2013/01/01 2
30 img6 last 2012/12/15 3
22 img5 last 2012/12/14 4
1 img1 last 2012/12/11 5
10 img4 last 2012/12/11 6
そして最終結果はこんな感じになります
id_gallery source status post position
30 img6 last 2012/12/15 3
22 img5 last 2012/12/14 4
1 img1 last 2012/12/11 5
10 img4 last 2012/12/11 6
2ページ目(例:gallery.php)にはたくさんの画像があるので、画像の正しい位置を知りたいです。そして、最初のページ(test1.php)で、ステータスが最後の5 imgを選択し、DESCの投稿で並べ替えます。ページgallery.phpへのリンクを作成したいのですが、正しい位置が必要です。正しい位置になったら、各画像へのリンクを作成できます。これは次のようになります。
<a href='http://localhost/testing/gallery/<?=$result[position]?>.htm'><img src='http://localhost/testing/<?=$result[source]?>.jpg' /></a>
//またはhtmlでは次のようになります
<a href='http://localhost/testing/gallery/1.htm'><img src='http://localhost/testing/img6.jpg' /></a>
したがって、正しい行位置を取得できれば、ページに正しくリンクするリンクを作成できます。
誰かが私にそれを達成する方法を教えてもらえますか?私はあなたの答えに感謝します、thx前に