使用第一个对象值更新表的列

时间:2017-02-28 06:36:00

标签: php json

我有一个json数组,这是我的json行的一行,我如何将38放到id38列和39id39列。 Automaticaly? Please see This Photo

这是我的代码:

<?php
$con=mysqli_connect("localhost","root","","array");
mysqli_set_charset($con,"utf8");
if (mysqli_connect_errno()){
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
$sql="SELECT `survey_answers`,us_id FROM `user_survey`";
if ($result=mysqli_query($con,$sql)){
    while ($row = mysqli_fetch_row($result)){
        $json = $row[0];
        if(!is_null($json)){                           
        //$json = preg_replace("!\r?\n!", "", $json);
        $jason_array = json_decode($json,true);
            $id = array();
            foreach ($jason_array as $data) {
            if (array_key_exists('id', $data)) {
            $id[] = $data['id'];
            }
            }
             $ids= implode(', \r\n',$id); 
            $sql1="update user_survey set id38='$ids' where us_id=".$row[1];
            echo $sql1."<br>";
            mysqli_query($con,$sql1);
        }
    }
}
mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:1)

尝试做这样的事情:

Image tempPlaceholder = Image.createImage(
        ParametresGeneraux.SIZE_OF_REPORT_PIC_IN_PX,
        ParametresGeneraux.SIZE_OF_REPORT_PIC_IN_PX,
        ParametresGeneraux.accentColor);
Graphics gr = tempPlaceholder.getGraphics();
gr.setAntiAliased(true);
gr.setColor(ParametresGeneraux.accentColor);
gr.fillArc(0, 0, ParametresGeneraux.SIZE_OF_REPORT_PIC_IN_PX, ParametresGeneraux.SIZE_OF_REPORT_PIC_IN_PX, 0, 360);

myComponent.setIcon(tempPlaceholder);


...


//Then call this at the end of everything
Display.getInstance().callSerially(() -> {
    EncodedImage roundPlaceholder = EncodedImage.createFromImage(tempPlaceholder, true);

    final Image reportImage = URLImage.createToStorage(
                        roundPlaceholder,
                        photoFilenameInStorage,
                        currentReport.getPhotoPath(),
                        ParametresGeneraux.RESIZE_SCALE_WITH_ROUND_MASK
                );
    myComponent.setIcon(reportImage);
    myComponent.getComponentForm().repaint();
});

DEMO