How to traverse the database to implement a list of multiple images in one row and implement the paging function

Source: Internet
Author: User
How can I traverse the database to implement a list of multiple images in one row and the paging function !! You can traverse the database to implement a list of multiple images in one row and the paging function. it is best to have the instance code.


Reply to discussion (solution)

Isn't it paging ??

As for the arrangement of your images, that is your layout problem.

Unlike normal paging

This is not implemented solely by databases.

Urgent !! You can traverse the database to implement a list of multiple images in one row and the paging function. it is best to have the instance code.
Ask !! How to layout,

Reply by referencing mylikr:
Urgent !! You can traverse the database to implement a list of multiple images in one row and the paging function. it is best to have the instance code.

Ask !! How to layout,
Isn't layout a problem with CSS?


So far!

The layout is simple. There are many methods.

For example, you have 10 images.

Of course, there are two pages.

The first page is eight.

When you output data, a new line is output to the fourth line.

Of course, you can use p + css for control. In short, there are many methods...

The layout is simple. There are many methods.

For example, you have 10 images.

Of course, there are two pages.

The first page is eight.

When you output data, a new line is output to the fourth line.

Of course, you can use p + css for control. In short, there are many methods...



I use php to traverse the database to get the data output in the image table, but I do the traversal, only need to make an image box, and then output all the images through the loop (I have done it before, however, the output is a row of images. I am wondering how to arrange the output Images From left to right (for example, to put four images in one row )?

$ Num = 4; // number of sheets per line
$ I = 0; // counter
While ($ row = mysql_fetch_assoc ($ rs )){
If ($ I = 0) echo'';
Echo''. $ Row ['image field name'].'';
$ I = ($ I + 1) % $ num;
If ($ I = 0) echo'';
}
If ($ I! = 0) echo'';

I use php to traverse the database to get the data output in the image table, but I do the traversal, only need to make an image box, and then output all the images through the loop (I have done it before, however, the output is a row of images. I am wondering how to arrange the output Images From left to right (for example, to put four images in one row )?
Your question falls into the category of the front-end artist. since you asked, I will talk to you briefly. it is actually very simple, but it is just a matter of control during the cycle.
I will give two examples. The first is table, and the second is p layout.

Echo "
 
  ";For($i=0;$i<10;$i++){IF($i % 3==0){IF($i>0){Echo "
  
    ";}Else{Echo "
   
    ";}}Else{Echo "
    ";}}Echo "
   
1
";


Below is the second method
This method requires css control.
# Box p {float: left; width: 33% ;}
Echo "

";For($i=0;$i<10;$i++){Echo "

1

";}Echo "

";

echo "
 
  ";$i = 1;foreach($arr as $value){$str = "
  ";if($i%3==0 || $i==1)echo $i == 1 ? "
   
    ".$str : $str."
   ";elseecho $str;$i++;}echo "
  
$value
";

$ Value can be changed to the image address by yourself.

$ Num = 4; // number of sheets per line
$ I = 0; // counter
While ($ row = mysql_fetch_assoc ($ rs )){
If ($ I = 0) echo'';
Echo''. $ Row ['image field name'].'';
$ I = ($ I + 1) % $ num;
If ($ I = 0) echo''; // Is to add if the outputWill change the line again .....
}
If ($ I! = 0) echo''; All I want to reference is his algorithm.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.