search

Home  >  Q&A  >  body text

PHP MYSQL loops to output a single piece of data in sequence

I want to make a loop to output pictures in sequence. Don’t know how to write this code?

Table structure

          1
##                        id

              img

            key

              date

h1.jpg

1 1522077253
2 h1.jpg
# 1 1522077253
3 h1.jpg
# 2 1522077253
4 h1.jpg
# 2 1522077253
5 h1.jpg
# 1 1522077253
6 h1.jpg
# 2 1522077253
7 h1.jpg
# 1 1522077253
8 h1.jpg
# 3 1522077253
9 h1.jpg
# 3 1522077253
10 h1.jpg
# 1 1522077253
# 11 h1.jpg
# 1 1522077253
12 h1.jpg
# 2 1522077253
13 h1.jpg
# 3 1522077253
14 h1.jpg
# 2 1522077253
15 h1.jpg
# 2 1522077253
16 h1.jpg
# 3 1522077253
17 h1.jpg
# 2 1522077253
18 h1.jpg
# 3 1522077253
19 h1.jpg
# 3 1522077253


For example, the field ID of key=1 is 1,2,5,7,10,11 six fields

I want to output one at a time in order.

The 1st time output id 1 field

The 2nd time output id 2 field

......

The 6th time output id 11 fields

The 7th time output id 1 field

The 8th time output id 2 fields

......

The Nth time Output the next field of id


The loop will continue forever.

No matter how many data with key=1 are inserted in the middle, the loop will continue.



How to write this PHP.

Currently I found a sequential output sql but it is inconvenient to use

select * from tu_pic order by field(id,9,5,6,7,8) limit 1


小涛 小涛 2481 days ago1704

reply all(3)I'll reply

  • 小涛

    小涛 2018-04-03 21:31:50

    I solved it myself. In fact, it is to play every song in an infinite loop

    reply
    0
  • sky

    sky2018-04-03 21:29:38

    I don’t understand what you want to do


    reply
    0
  • 好人二狗

    好人二狗2018-03-29 12:19:43

    I didn’t do what you did, this should be an infinite loop,

    $sql = 'select * from tu_pic order by id desc limit 1'

    for ($i=0; ;$i++) {

    $reult = mysql_query($sql);

    var_dump(mysql_fetch_array($result));
    }

    reply
    0
  • Cancelreply