How to group values and process them for the comic?

Asked

Viewed 110 times

2

I have a BD that contains 16 fields of information, this BD keeps bets placed on a system, to later be able to process the result and payment of the customer’s ticket.

In the administration part, ADM has an area where it is possible to place the results of the games that were made by the customer, when the customer makes a bet, is stored the name of the team, the type of bet, and the match.

For example, have a game of Vasco and Flamengo, you bet that Vasco will make 2 goals in the second half, in BD I store this information as follows:

Name of the team: Vasco.

Type of bet: +2.

Clash: Vasco x Flamengo.

In the administrative part, ADM has to check all the games that are in BD, except that several customers make the same type of bet, IE, I will have in BD 15,20 repeated records, with the same Team name, even Type of bet and even Showdown.

The Administrator, makes the conference of the games, for a select, i print all BD records in one, select has 3 options, "won, lost, canceled". and by the ID of that confrontation log, I can update the result in the BD.

But the problem, is that it has many repeated results, and it becomes complicated for the administrator to put the same result in several equal games, example: Print do sistema com jogos repetidos

What I want, is to group these games, based on the same match, Wager and Wager condition, and the result that the administrator put in select, worth for all of the same group, without having to put the same result several times. In PHP I can group in the sql:

$conexao->prepare('SELECT time_apostado,tipojogo,tipoaposta,codigo  FROM bilhetes_temp WHERE codigo GROUP BY time_apostado,tipojogo,tipoaposta');

But I have no idea how to show only 1 result to the admin, and make the result of the select he puts, worth to all others who are equal.

So someone give me an idea of how I group these results in the PHP or also in the JasvaScript?

  • I don’t quite understand how you intend to group this result. Can explain better?

  • I want to group them in a single select, so that it is possible for the administrator to insert the result in one, and the same goes for the repeated results.

  • Just to better understand... the administrator will put the right game result? There with this original result he will make the selection of bettors who have hit the result... That’s what you want?

  • If that’s it... you have to create a separate table. type resultado_original and then compare it with the betting table to select only the winning bets. if you need me I’ll make the answer for you

  • You can also create a field in the table called status.. if 0 is still in check... if 1 is the user hit... if 2 is the user missed... so when the administrator posts the actual game result.. it will make an UPDATE in the table where the original result is = the result of the bettors... with this you will make a single select in the same table where all bets have the status = 1... if you want I can create this example

  • André, this I already did, 0 for lost and 1 for won, only that the system contains many repeated games, so I wanted that when there were for example; two games with the same values, so in addition to show the admin these two repeated games, I wanted to appear only 1, In this '1' he would put the result if he won or lost, then the script would give the UPDATE in all games that are equal, ie the same type of bet, without it being necessary to put several times the result in repeated games. I could tell?

  • Yes... I think I understand... but I think you are not optimizing your code... see... instead of the admin selecting 1 to say that all the games with that such result won... the administrator simply put the result of the game in a form and in another file you redeems these values and automatically changes in all WHERE result = $_POST.... what do you think?

  • I don’t know if this field exists in the table... but I find it interesting each game to have a unique nuneraçao... for example... flamengo x santos... numero set: 5... Vasco x palmeiras... game number 6... so you can do the GROUP BY the way you want because you group the bets by the number of the game... in the case of games of Vasco x palmeiras would stay GROUP BY 6

  • already solved @Cassianojose this question? You tested the solution I posted as an answer ?

  • It worked right! thank you very much Sneeps and sorry for the delay.

Show 5 more comments

1 answer

1


To make a table inside another table, it would be like a 'details' for each result that is equal, see an example of a plugin jqWidget:

inserir a descrição da imagem aqui

With a little patience I managed to use to group by code: inserir a descrição da imagem aqui

Follow an encoded example of the plugin usage:

    <!DOCTYPE html>
<html lang="en">
<head>
    <title id='Description'>This example shows how to display nested Grid plugins.</title>
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.filter.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.sort.js"></script>
    <script type="text/javascript" src="../../scripts/demos.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var url = "../sampledata/employees.xml";
            var source =
            {
                datafields: [
                    { name: 'FirstName' },
                    { name: 'LastName' },
                    { name: 'Title' },
                    { name: 'Address' },
                    { name: 'City' }
                ],
                root: "Employees",
                record: "Employee",
                id: 'EmployeeID',
                datatype: "xml",
                async: false,
                url: url
            };
            var employeesAdapter = new $.jqx.dataAdapter(source);
            var orderdetailsurl = "../sampledata/orderdetails.xml";
            var ordersSource =
            {
                datafields: [
                    { name: 'EmployeeID', type: 'string' },
                    { name: 'ShipName', type: 'string' },
                    { name: 'ShipAddress', type: 'string' },
                    { name: 'ShipCity', type: 'string' },
                    { name: 'ShipCountry', type: 'string' },
                    { name: 'ShippedDate', type: 'date' }
                ],
                root: "Orders",
                record: "Order",
                datatype: "xml",
                url: orderdetailsurl,
                async: false
            };
            var ordersDataAdapter = new $.jqx.dataAdapter(ordersSource, { autoBind: true });
            orders = ordersDataAdapter.records;
            var nestedGrids = new Array();
            // create nested grid.
            var initrowdetails = function (index, parentElement, gridElement, record) {
                var id = record.uid.toString();
                var grid = $($(parentElement).children()[0]);
                nestedGrids[index] = grid;
                var filtergroup = new $.jqx.filter();
                var filter_or_operator = 1;
                var filtervalue = id;
                var filtercondition = 'equal';
                var filter = filtergroup.createfilter('stringfilter', filtervalue, filtercondition);
                // fill the orders depending on the id.
                var ordersbyid = [];
                for (var m = 0; m < orders.length; m++) {
                    var result = filter.evaluate(orders[m]["EmployeeID"]);
                    if (result)
                        ordersbyid.push(orders[m]);
                }
                var orderssource = { datafields: [
                    { name: 'EmployeeID', type: 'string' },
                    { name: 'ShipName', type: 'string' },
                    { name: 'ShipAddress', type: 'string' },
                    { name: 'ShipCity', type: 'string' },
                    { name: 'ShipCountry', type: 'string' },
                    { name: 'ShippedDate', type: 'date' }
                ],
                    id: 'OrderID',
                    localdata: ordersbyid
                }
                var nestedGridAdapter = new $.jqx.dataAdapter(orderssource);
                if (grid != null) {
                    grid.jqxGrid({
                        source: nestedGridAdapter, width: 780, height: 200,
                        columns: [
                          { text: 'Ship Name', datafield: 'ShipName', width: 200 },
                          { text: 'Ship Address', datafield: 'ShipAddress', width: 200 },
                          { text: 'Ship City', datafield: 'ShipCity', width: 150 },
                          { text: 'Ship Country', datafield: 'ShipCountry', width: 150 },
                          { text: 'Shipped Date', datafield: 'ShippedDate', width: 200 }
                       ]
                    });
                }
            }
            var photorenderer = function (row, column, value) {
                var name = $('#jqxgrid').jqxGrid('getrowdata', row).FirstName;
                var imgurl = '../../images/' + name.toLowerCase() + '.png';
                var img = '<div style="background: white;"><img style="margin:2px; margin-left: 10px;" width="32" height="32" src="' + imgurl + '"></div>';
                return img;
            }
            var renderer = function (row, column, value) {
                return '<span style="margin-left: 4px; margin-top: 9px; float: left;">' + value + '</span>';
            }
            // creage jqxgrid
            $("#jqxgrid").jqxGrid(
            {
                width: 850,
                height: 365,
                source: source,
                rowdetails: true,
                rowsheight: 35,
                initrowdetails: initrowdetails,
                rowdetailstemplate: { rowdetails: "<div id='grid' style='margin: 10px;'></div>", rowdetailsheight: 220, rowdetailshidden: true },
                ready: function () {
                    $("#jqxgrid").jqxGrid('showrowdetails', 1);
                },
                columns: [
                      { text: 'Photo', width: 50, cellsrenderer: photorenderer },
                      { text: 'First Name', datafield: 'FirstName', width: 100, cellsrenderer: renderer },
                      { text: 'Last Name', datafield: 'LastName', width: 100, cellsrenderer: renderer },
                      { text: 'Title', datafield: 'Title', width: 180, cellsrenderer: renderer },
                      { text: 'Address', datafield: 'Address', width: 300, cellsrenderer: renderer },
                      { text: 'City', datafield: 'City', width: 170, cellsrenderer: renderer }
                  ]
            });
        });
    </script>
</head>
<body class='default'>
    <div id="jqxgrid">
    </div>
</body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.