PHP peer-to-peer loop, online, etc., adding 100 points

Source: Internet
Author: User
PHP peer-to-peer loop, online, etc. you cannot upload images after adding 100 points to csdn. please refer to Baidu for the data table structure picture.
Http://zhidao.baidu.com/question/1047510947746416459.html
This is my data table structure, PHP + MYSQL. I want to achieve the effect of loop.

Size color pattern

36 red prints

36 red fl

36 White prints

36 white flat

36 black print

36 white flat

37 red prints

37 red flat

And so on, but the size, color, and pattern are not fixed. There may be only two

Size color

36 red

36 White

36 Black

37 Red

37 White

...... And so on

There may also be four sizes, colors, patterns, and others.

In this way, how can we use the table format loop... I can use FOR to loop out, but it can only be fixed and cannot be chosen freely.


Reply to discussion (solution)

Are your size, color, and pattern values in one field? What are used to separate them? What is the data type?

Look at this test example and you should know how to do it.

Create temporary table a ('size' varchar (10) charset gbk; insert into a values (36), (37 ); create temporary table B ('color' varchar (10) charset gbk; insert into B values ('red'), ('white'), ('lan '), ('black'); create temporary table c ('Pattern 'varchar (10) charset gbk; insert into c values ('Taobao'), ('flate '); select * from a, B, c;
Size color pattern 36 red print 37 red print 36 red flat 37 red flat 36 white print 37 white flat 37 white flat 36 blue print 37 blue print 36 blue flat 37 blue flat 36 black print 37 black print 36 black flat 37 black flat

For each product, we first list some products.
For example, the size, color, and pattern have three arrays: size, color, and pattern.
For example, the size and color are only two arrays.

Then loop.

Are your size, color, and pattern values in one field? What are used to separate them? What is the data type?


The size and color pattern are in three records respectively. For example, all values of a size are separated by \ n in one field.

For each product, we first list some products.
For example, the size, color, and pattern have three arrays: size, color, and pattern.
For example, the size and color are only two arrays.

Then loop.



It can be divided into three arrays, but I will not loop.

Example

$ar = array(  array( "A",  "B",  "C"),  array("1",  "2",  "3", "4"),  array("X",  "Y",  "Z"),);print_rDescartes($ar));function Descartes($d) {  $r = array_pop($d);  while($d) {    $t = array();    $s = array_pop($d);    if(! is_array($s)) $s = array($s);    foreach($s as $x) {      foreach($r as $y) $t[] = array_merge(array($x), is_array($y) ? $y : array($y));    }    $r = $t;  }  return $r;}

Example

$ar = array(  array( "A",  "B",  "C"),  array("1",  "2",  "3", "4"),  array("X",  "Y",  "Z"),);print_rDescartes($ar));function Descartes($d) {  $r = array_pop($d);  while($d) {    $t = array();    $s = array_pop($d);    if(! is_array($s)) $s = array($s);    foreach($s as $x) {      foreach($r as $y) $t[] = array_merge(array($x), is_array($y) ? $y : array($y));    }    $r = $t;  }  return $r;}



All points are for you. Thank you for helping me

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.