php - display associative array containing product info brand by brand -


I have developed a code in php, where I can get product information from database and save it in an associative array And then I can display it according to my layout. Now the problem for me is that when I select the product from the database table, its bulk means that if I take 1000 records of 3 brand estimates. I want to show them as a product for a brand, then repeat the matter for the third and the number of products for the second. I want to display a product name according to a brand name. My array is in php, which I am developing with PHP

  $ firstsql = 'SELECT * to xml where (' .implode ('and', $ parts1). ')'; $ Firstsql3 = mysql_query ($ firstsql); $ First = array (); While ($ line = mysql_fetch_array ($ firstsql3)) {$ first [] = $ line; }   

And then, doing this erratically using foreach loop through this array. If I have 300 records for the first brand, 200 for the second and 500 for the third. I want to iterate like this

Please guide me how to do this ...

Code for array display format

    

Tried the following code but did not work properly

  & lt; Php $ firstsql = 'SELECT * from xml'; Print ($ firstsql); $ Firstsql3 = mysql_query ($ firstsql); $ First = array (); While ($ line = mysql_fetch_array ($ firstsql3)) {$ first [] = $ line; } $ Brand1 = array (); $ Brand2 = array (); $ Brand3 = array (); // Product different by brand foreach ($ $ as first $) {if ($ v ['brand'] == 1) {$ brand1 [] = $ v; } And if ($ V ['brand'] == 2) {$ brand2 [] = $ v; } And if ($ v ['brand'] == 3) {$ brand3 [] = $ v; }} // Number of product number for each brand $ brand1_c = count ($ brand1); $ Brand2_c = Count ($ brand2); $ Brand3_c = count ($ brand3); Echo $ brand1_c; Echo $ brand2_c; // Final product array $ end = array () start; // Get the highest number from each brand products $ supreme_number = maximum ($ brand1_c, $ brand2_c, $ brand3_c); // Based on the highest count ($ i = 1; $ i & lt; $ supreme_number; $ i ++) {// Check that array key is present, if (array_key_exists ($ i, $ brand1)) {// Final Product Array $ Add Product Details at Last [] = $ brand1 [$ i]; } // Check that if the array key is present or not, add product details in brand 2 if (array_key_exists ($ i, $ brand2)) {// final product array $ last [] = $ brand2 [$ i]; } // Check that the array key exists or if not for brand3 (array_key_exists ($ i, $ brand3)) {// Product Product Description Add final product array $ last [] = $ brand3 [$ i]; }} Foreach ($ $ as Last $) {$ i; ? & Gt; & Lt; Div & gt; & Lt; img src = "& lt ;? php echo $ array ['IMAGEURL']? & gt;" /> & Lt; / Div & gt; & Lt ;? Php $ i ++; }? & Gt;    

try it ......

 < code> $ Firstsql = 'SELECT * to xml where (' .implode ('and', $ parts1). ')'; $ Firstsql3 = mysql_query ($ firstsql); $ First = array (); While ($ line = mysql_fetch_array ($ firstsql3)) {$ first [] = $ line; } $ Brand1 = array (); $ Brand2 = array (); $ Brand3 = array (); // Product different by brand foreach ($ $ as first $) {if ($ v ['brand'] == 1) {$ brand1 [] = $ v; } And if ($ v ['brand'] == 2) {$ brand2 [] = $ v; } And if ($ v ['brand'] == 3) {$ brand3 [] = $ v; }} // Calculate the number of products for each brand $ brand1_c = count ($ brand1); $ Brand2_c = Count ($ brand2); $ Brand3_c = count ($ brand3); // Final product array $ end = array () start; // Get the highest number from each brand products $ supreme_number = maximum ($ brand1_c, $ brand2_c, $ brand3_c); // Go to the top calculation based on ($ i = 1; $ i & lt; $ top_number; $ i ++) // Check if array key exists or if (array_key_exists ($ i , $ Brand1)) {// Final Product Array $ Add Product Details At Last [] = $ brand1 [$ i]; } // Check that if the array key is present or not, add product details in brand 2 if (array_key_exists ($ i, $ brand2)) {// final product array $ last [] = $ brand2 [$ i]; } // Check that the array key exists or if not for brand3 (array_key_exists ($ i, $ brand3)) {// Product Product Description Add final product array $ last [] = $ brand3 [$ i]; }}    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -