Jump to content

Ref_Id in mysql table with php


mehidy

Recommended Posts

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-table

id---ref_id
1----55
2----55
3----55
4----55
5----55
6----56
7----56
8----56
9----56
10----56

Link to comment
Share on other sites

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#46463308

Now 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.

Link to comment
Share on other sites

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
                )

        )

)
*******************************************************/
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.