Advertisement
BankUpload Join!

Thursday, April 14, 2016

Download a jpg image from web into a TImage in android app

for show a image from a internet source into a timage you can this sample code


procedure TForm24.Button1Click(Sender: TObject);

var
  s: TStream;
  uri:String;
begin
     uri:='http://bankupload.com/images_mega/map.png';
  s := TMemoryStream.Create;

  with TIdHTTP.Create(nil) do
  try
    Get(uri, s);
    Image1.Bitmap.LoadFromStream(s);
  finally
    Free;
    s.Free;
  end;
  showMessage('.');
end;

How to Convert Data from MySQL to JSON using PHP

converted mysql to json using php. Here is the complete PHP code for it.
<?php
    //open connection to mysql db
    $connection = mysqli_connect("hostname","username","password","db_employee") or die("Error " . mysqli_error($connection));

    //fetch table rows from mysql db
    $sql = "select * from tbl_employee";
    $result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));

    //create an array
    $emparray = array();
    while($row =mysqli_fetch_assoc($result))
    {
        $emparray[] = $row;
    }
    echo json_encode($emparray);

    //close the db connection
    mysqli_close($connection);
?>
If you want to write the data from mysql to json file, use this piece of code at the end instead of 'echo' statement.
<?php
    //write to json file
    $fp = fopen('empdata.json', 'w');
    fwrite($fp, json_encode($emparray));
    fclose($fp);
?>