1

I want to select some data from a cross server using PHP foreach and curl by pass it to a table.

I want to query the result of draw two times per day example: from

2015-12-08 13:00 and

2015-12-08 18:00 and I will display it as the correct imagesThis is the correct result it will display like this But what I got from this function is like this I don't know how to play my table as above images

public function getNumber() {

    $url = "http://103.5.126.24/PalmHallServer_kl/coodraw/coodraw!queryLuckNumberRecordByPeriods.action";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: Json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $contents = curl_exec($ch);
    if($contents){
        echo $contents;
    }else{
        return FALSE;
    }
}

Here is Ajax

 $.get('<?PHP echo base_url('getnumber'); ?>', function (ldata, status) {

            var $json = $.parseJSON(ldata);
            $("#results").html("");

            var result = [];
            $.each(eval($json), function (i, val) {
                if (val.productName == 'DRAW1') {
                    result = val.luckNumber;
                }
                if (val.productName == 'DRAW2') {
                    result = val.luckNumber;
                }
                if (val.productName == 'DRAW3') {
                    result = val.luckNumber;
                }
                if (val.productName == 'DRAW4') {
                    result = val.luckNumber;
                }
                var table = '<td>' + result + '</td>';
                $(table).appendTo('#results');
            });
        });

This is data aft There is alot of result but I selected only a day You can see on this link

[http://103.5.126.24/PalmHallServer_kl/coodraw/coodraw!queryLuckNumberRecordByPeriods.action][3]
[{"betEndtime":null,"betStartime":"2014-01-19 13:00:00","createTime":"2015-12-08 13:00:09","id":100005553,"lotteryOpenStatus":5,"lotteryOpenTime":"2015-12-08 13:00:00","lotteryType":11,"luckNumber":"22522","luckNumberSource":"","operatorName":"auto_open_draw","operatorTeleno":"","orderId":"","periods":"201512081300","prizeNumCode":0,"prizeNumLevel":1,"productId":11111,"productJson":{"baseTime":20140119130000,"commissionRatio":10,"deductBetCount":1,"detail":"","enable":1,"freeResDiscount":1,"lotteryTime":20151208180000,"luckDrawDesc":"DRAW1","luckDrawDiscount":1,"maxLuckNumLen":5,"maxMoney":2000000,"minLuckNumLen":5,"minMoney":100,"nextStartTime":"2015-12-08 13:00:00","nextStopTime":"2015-12-08 17:45:00","openDrawType":0,"periodUnit":1,"periodUnitNum":1,"price":40,"productCode":"DRAW1","productDesc":"Draw1","productEndTime":20990119163000,"productId":11111,"productType":11,"rate":0,"resTmplProductId":11111,"stopTime":900,"validPeriod":2},"productName":"DRAW1","publicTime":null,"rewardMultiple":0,"updateTime":"2015-12-08 13:01:22","winAmount":0},{"betEndtime":null,"betStartime":"2014-01-19 13:00:00","createTime":"2015-12-08 13:00:15","id":100005554,"lotteryOpenStatus":5,"lotteryOpenTime":"2015-12-08 13:00:00","lotteryType":11,"luckNumber":"29848","luckNumberSource":"","operatorName":"auto_open_draw","operatorTeleno":"","orderId":"","periods":"201512081300","prizeNumCode":0,"prizeNumLevel":1,"productId":11112,"productJson":{"baseTime":20140119130000,"commissionRatio":10,"deductBetCount":1,"detail":"","enable":1,"freeResDiscount":1,"lotteryTime":20151208180000,"luckDrawDesc":"DRAW2","luckDrawDiscount":1,"maxLuckNumLen":5,"maxMoney":2000000,"minLuckNumLen":5,"minMoney":100,"nextStartTime":"2015-12-08 13:00:00","nextStopTime":"2015-12-08 17:45:00","openDrawType":0,"periodUnit":1,"periodUnitNum":1,"price":40,"productCode":"DRAW2","productDesc":"Draw2","productEndTime":20990119163000,"productId":11112,"productType":11,"rate":0,"resTmplProductId":11112,"stopTime":900,"validPeriod":2},"productName":"DRAW2","publicTime":null,"rewardMultiple":0,"updateTime":"2015-12-08 13:02:32","winAmount":0},{"betEndtime":null,"betStartime":"2014-01-19 13:00:00","createTime":"2015-12-08 13:00:18","id":100005555,"lotteryOpenStatus":5,"lotteryOpenTime":"2015-12-08 13:00:00","lotteryType":11,"luckNumber":"35495","luckNumberSource":"","operatorName":"auto_open_draw","operatorTeleno":"","orderId":"","periods":"201512081300","prizeNumCode":0,"prizeNumLevel":1,"productId":11113,"productJson":{"baseTime":20140119130000,"commissionRatio":10,"deductBetCount":1,"detail":"","enable":1,"freeResDiscount":1,"lotteryTime":20151208180000,"luckDrawDesc":"DRAW3","luckDrawDiscount":1,"maxLuckNumLen":5,"maxMoney":2000000,"minLuckNumLen":5,"minMoney":100,"nextStartTime":"2015-12-08 13:00:00","nextStopTime":"2015-12-08 17:45:00","openDrawType":0,"periodUnit":1,"periodUnitNum":1,"price":40,"productCode":"DRAW3","productDesc":"Draw3","productEndTime":20990119163000,"productId":11113,"productType":11,"rate":0,"resTmplProductId":11113,"stopTime":900,"validPeriod":2},"productName":"DRAW3","publicTime":null,"rewardMultiple":0,"updateTime":"2015-12-08 13:03:27","winAmount":0},{"betEndtime":null,"betStartime":"2014-01-19 13:00:00","createTime":"2015-12-08 13:00:21","id":100005556,"lotteryOpenStatus":5,"lotteryOpenTime":"2015-12-08 13:00:00","lotteryType":11,"luckNumber":"89346","luckNumberSource":"","operatorName":"auto_open_draw","operatorTeleno":"","orderId":"","periods":"201512081300","prizeNumCode":0,"prizeNumLevel":1,"productId":11114,"productJson":{"baseTime":20140119130000,"commissionRatio":10,"deductBetCount":1,"detail":"","enable":1,"freeResDiscount":1,"lotteryTime":20151208180000,"luckDrawDesc":"DRAW4","luckDrawDiscount":1,"maxLuckNumLen":5,"maxMoney":2000000,"minLuckNumLen":5,"minMoney":100,"nextStartTime":"2015-12-08 13:00:00","nextStopTime":"2015-12-08 17:45:00","openDrawType":0,"periodUnit":1,"periodUnitNum":1,"price":40,"productCode":"DRAW4","productDesc":"Draw4","productEndTime":20990119163000,"productId":11114,"productType":11,"rate":0,"resTmplProductId":11114,"stopTime":900,"validPeriod":2},"productName":"DRAW4","publicTime":null,"rewardMultiple":0,"updateTime":"2015-12-08 13:04:26","winAmount":0}]
7
  • 1
    Do you know what are the numbers in the other columns in your result? Can you paste your $contents? Did you code the funcion on the other server or it's maintained by somebody else? Commented Dec 8, 2015 at 17:35
  • @Marek Galinski, This is right I will select from 103.5.126 server and past data on my website I Commented Dec 8, 2015 at 17:42
  • 1
    Good, can you paste the raw $contents retrieved from your curl somewhere on pastebin? Thx Commented Dec 8, 2015 at 17:44
  • 1
    So the data you get are correct (visually), only the formatting on the page is wrong? Commented Dec 8, 2015 at 17:59
  • 1
    Let us continue this discussion in chat. Commented Dec 8, 2015 at 18:00

1 Answer 1

1

Change the AJAX code to following:

$("#results").html("");

var result = [];
var table = '';
tmpDRAW1 = '';
tmpDRAW2 = '';
tmpDRAW3 = '';
tmpDRAW4 = '';
tmpCounter = 0;

$.each(eval($json), function(i, val) {
  tmpOpenTime = val.lotteryOpenTime;

  if (val.productName == 'DRAW1') {
    tmpDRAW1 = val.luckNumber;
    tmpCounter++;
  }
  if (val.productName == 'DRAW2') {
    tmpDRAW2 = val.luckNumber;
    tmpCounter++;
  }
  if (val.productName == 'DRAW3') {
    tmpDRAW3 = val.luckNumber;
    tmpCounter++;
  }
  if (val.productName == 'DRAW4') {
    tmpDRAW4 = val.luckNumber;
    tmpCounter++;
  }

  if (tmpCounter == 4) {
    table += '<tr><td>' + tmpOpenTime + '</td>';
    table += '<td>' + tmpDRAW1 + '</td>';
    table += '<td>' + tmpDRAW2 + '</td>';
    table += '<td>' + tmpDRAW3 + '</td>';
    table += '<td>' + tmpDRAW4 + '</td></tr>';
    tmpCounter = 0;
  }

});
$(table).appendTo('#results');
});

This does the output format you want, and is resistant to ordering of DRAWs in your JSON.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm really thanks you very much for your helping us. It is awesome

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.