Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can i store data of database's different categories

How can i store data of database's different categories

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 956 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kuji
    wrote on last edited by
    #1

    I want to export data into CSV format, i have this table it has column for customer id, product category id and price of product that customer bought.
    edfb274f-9955-4b4d-a21b-9c270592f9b6-image.png
    I want to export below table to CSV for all products. First row is customer id and column under every customer id is prices of products that customer bought.

    The question is how can i store data of prices by user and product. I tryed to use queries and arrays, but i don't know how many there will be values.

    0a493374-6356-44a7-a630-aef8f1b52b6b-image.png

    To export to CSV i store all data in QString value with ';' for next column and \n for next row and then transimt QString value.

    C 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why do you need to know the exact number of rows ?

      Just loop over the result of your query and add one line for each row the query returned.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why do you need to know the exact number of rows ?

        Just loop over the result of your query and add one line for each row the query returned.

        K Offline
        K Offline
        Kuji
        wrote on last edited by Kuji
        #3

        @SGaist How can create query if there can be any amount of customers and products? The problem is i can't just take all prices, because they have different categories.

        Looks like query should store prices by queue from 0 to last customer, and after last customer's price again 0 to last customer, but i can't figure out how to do this.

        1 Reply Last reply
        0
        • K Kuji

          I want to export data into CSV format, i have this table it has column for customer id, product category id and price of product that customer bought.
          edfb274f-9955-4b4d-a21b-9c270592f9b6-image.png
          I want to export below table to CSV for all products. First row is customer id and column under every customer id is prices of products that customer bought.

          The question is how can i store data of prices by user and product. I tryed to use queries and arrays, but i don't know how many there will be values.

          0a493374-6356-44a7-a630-aef8f1b52b6b-image.png

          To export to CSV i store all data in QString value with ';' for next column and \n for next row and then transimt QString value.

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          @Kuji Let me see if I have this straight. You want to take the table of data you show and produce this table with an unbounded number of columns (one per customer), a header row containing the customer number for each column, and an unbounded number of rows (as many rows as the maximum number of orders made by any customer).

          0       1       2
          1999    2499    1399
          1349    null    null
          
          K 1 Reply Last reply
          0
          • C ChrisW67

            @Kuji Let me see if I have this straight. You want to take the table of data you show and produce this table with an unbounded number of columns (one per customer), a header row containing the customer number for each column, and an unbounded number of rows (as many rows as the maximum number of orders made by any customer).

            0       1       2
            1999    2499    1399
            1349    null    null
            
            K Offline
            K Offline
            Kuji
            wrote on last edited by
            #5

            @ChrisW67 Yes this is what i want.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              One issue with your CSV, you are losing the information about which product belongs to which prize unless you also state that each row corresponds to a product ID.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kuji
                wrote on last edited by
                #7

                Solved by creating QTableWidget. I transmited data from database in QTableWidget one query in a column and then row by row added data from QTableWidget to QString value to export it later to CSV.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved