title: Get data from PHP file on click of a button
body: <p>When you load the page, I have two separate divs that get images randomly from a database then echo them as the background-image. I also get other data that comes along with the image.</p>
  
  <p>I need to get data from a new PHP file and change the background-image of a div on click of a button (so that you don't need to refresh the page).</p>
  
  <p>In getnew.php:</p>
  
  <pre><code>$select = mysqli_select_db($conn, "database"); 
  
  $result = mysqli_query($conn,"SELECT * FROM photos ORDER BY rand() LIMIT 1");
  $row = $result-&gt;fetch_assoc();
  $img1link = $row['link'];
  $rating1 = $row['rating'];
  $s1 = $row['sigma'];
  
  $result2 = mysqli_query($conn,"SELECT * FROM photos ORDER BY rand() LIMIT 1");
  $row2 = $result2-&gt;fetch_assoc();
  $img2link = $row2['link'];
  $rating2 = $row2['rating'];
  $s2 = $row2['sigma'];
  </code></pre>
  
  <p>In main.php:</p>
  
  <pre><code>$("#button").on("click",function(){
      //
  })
  </code></pre>
  
  <p>As I understand it you use jQuery's $.get to fetch the data from getnew.php but how exactly can I then use the data to change the background-image without having to refresh the page?</p>
  
  <p>For example: <code>style="background-image: url('&lt;?php echo $img1link ?&gt;')"&gt;</code></p>