0

Trying to create a json encode with a ID and a image URL so i can reach it as a jobject in my frontend.

I am not working with a MySQL here as I store the images on my map/file manager.

I want it to look like this when when the code runs:

{
  results: [
  {
  ID: "3",
  URL: "http://www.image.com/Images/image3.jpg"
  }        ]
}

So I want to connect an image to a certain IP and also get its URL.

This is my code so far:

<?php 

    $contacts = array();

          $contact = array("URL" => $row ['http://www.image.com/Images/image1.jpg'],
          $row ['http://www.image.com/Images/image2.jpg'],
          $row ['http://www.image.com/Images/image3.jpg'],
          "ID" => $row ['1'], $row ['2'], $row ['3']);
          array_push($contacts, $contact);


    echo json_encode(array('results' => $contacts), JSON_PRETTY_PRINT);


?>

1 Answer 1

1

Still don't see $row.. Anyway, I think what you want is something like this :

<?php

    $contacts = array();

    $contacts[] = array("id"=>1,"URL"=>'http://www.image.com/Images/image1.jpg');
    $contacts[] = array("id"=>1,"URL"=>'http://www.image.com/Images/image2.jpg');
    $contacts[] = array("id"=>1,"URL"=>'http://www.image.com/Images/image3.jpg');

    echo json_encode(array('results' => $contacts), JSON_PRETTY_PRINT);

Example https://3v4l.org/uRbQ7

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

Comments

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.