Jump to content

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
https://forums.phpfreaks.com/topic/305147-ref_id-in-mysql-table-with-php/
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.

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
                )

        )

)
*******************************************************/
  • Like 2
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.