mehidy Posted September 28, 2017 Share Posted September 28, 2017 Hi I have a table with id auto increment , I have another field is ref_id, i want to add same numeric data in this field for every 5 row & after every 5 row it will auto crease the no#. Is this possible, if yes how can I do this?Here below , what I want to do?Mysql-tableid---ref_id1----552----553----554----555----556----567----568----569----5610----56 Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 28, 2017 Share Posted September 28, 2017 Can you explain "why" you want to do this? How are you going to use that value; what is its purpose? I have a feeling that what you are trying to achieve would be best handled more efficiently another way. Quote Link to comment Share on other sites More sharing options...
benanamen Posted September 28, 2017 Share Posted September 28, 2017 I basically said the same thing to the OP in the other forum he posted this too. This smells of an XY problem. OP, as I asked you in the other Forum, what is the real problem you are trying to solve? Quote Link to comment Share on other sites More sharing options...
mehidy Posted September 29, 2017 Author Share Posted September 29, 2017 Its a bit complicated. Please see below, i'm trying to explain.I'm getting some data from a xls file..from the file i'm getting column DEFG data under one field QTY in mysql table. See here https://stackoverflow.com/questions/46432063/getting-excel-row-data-to-mysql-column-in-php/46463308#46463308Now I need to retrieve the data from mysql table to show in a html table as is it is in the excel file. I mean like D-F-E-G column. I hope you got my point. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 29, 2017 Share Posted September 29, 2017 Store the query data in an array. Then you can loop through the array outputting each element into a row of your HTML table. /************************************************** ** SET UP AN EMPTY ARRAY FOR THE SIZES ***************************************************/ $sizes = [ 'XS' => 0, 'S' => 0, 'M' => 0, 'L' => 0 ]; /************************************************** ** PROCESS THE DATA ** STORE IN AN ARRAY ** the array will have 1 element for each output row ** each element has a subarray for the size/qty data ***************************************************/ $data = []; $sql = "SELECT style , color , orderno , size , qty FROM stock ORDER BY orderno"; $res = $db->query($sql); foreach ($res as $row) { if (!isset($data[$row['orderno']])) { $data[$row['orderno']]['style'] = $row['style']; $data[$row['orderno']]['color'] = $row['color']; $data[$row['orderno']]['style'] = $row['style']; $data[$row['orderno']]['sizes'] = $sizes; // initialize with empty sizes array } $data[$row['orderno']]['sizes'][$row['size']] = $row['qty']; // put qty in the sizes array } /******* SAMPLE RESULTING data ARRAY ***************** Array ( [123] => Array ( [style] => ABC123 [color] => WHITE [sizes] => Array ( [XS] => 100 [S] => 200 [M] => 300 [L] => 400 ) ) [124] => Array ( [style] => ABC123 [color] => NOIR [sizes] => Array ( [XS] => 500 [S] => 600 [M] => 700 [L] => 800 ) ) ) *******************************************************/ 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.