title: Retrieving data from database and automatize php scripts while using PhantomJS
body: <h2>Question 1</h2>
  
  <p>I am currently working on a project where I am trying to retrieve values from a table in a SQL database and insert them into a webpage. This is all on the server side, Linux. The only unique value is the ID, and depending on the number of the ID the webpage will change accordingly.</p>
  
  <p>For example:</p>
  
  <p>ID: 1, Color: Red.</p>
  
  <p>ID: 2, Color: Blue.</p>
  
  <p>If the ID value 1 is retrieved, the background color will change to red. And if ID 2 is retrieved, the background color is blue.</p>
  
  <p>The question is, is there a way to trigger this background color change using PHP and/or Javascript?</p>
  
  <h2>Question2</h2>
  
  <p>Now, when question 1 is answered, we have our webpage background color changed to a desired color. The next thing would be to take an image of our newly changed website. This will be done with PhantomJS (later on this will be made into a video, but that problem is solved).</p>
  
  <p>Is it possible to make all of this automatized? So that when the webpage has changed background color, the Go.php will start running?</p>
  
  <p>Thanks in advance!</p>
  
  <hr>
  
  <p>Relevant to Question 1</p>
  
  <p>Retrieves data from database</p>
  
  <p><strong>Takeinfo.php</strong></p>
  
  <pre><code>&lt;?php
  $dbhost = 'localhost';
  $dbuser = 'User';
  $dbpass = 'Password';
  $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  if(! $conn )
  {
    die('Could not connect: ' . mysql_error());
  }
  $sql = 'SELECT id, color FROM thevariables;
  
  mysql_select_db(TheDatabse);
  $retval = mysql_query( $sql, $conn );
  if(! $retval )
  {
    die('Could not get data: ' . mysql_error());
  }
  while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
  {
      echo "ID :{$row['id']}  &lt;br&gt; ".
           "Color :{$row['color']}  &lt;br&gt; ".
           "--------------------------------&lt;br&gt;";
  } 
  echo "Fetched data successfully\n";
  mysql_close($conn);
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>Relevant to Question 2</p>
  
  <p>Go.php will initiate run.sh, which in turn starts PhantomJS and proceeds to run runscript.js.</p>
  
  <p><strong>go.php</strong></p>
  
  <pre><code>&lt;?php 
  echo shell_exec('sh gogo.sh');
   ?&gt;
  </code></pre>
  
  <p><strong>run.sh</strong></p>
  
  <pre><code>phantomjs runscript.js
  </code></pre>
  
  <p><strong>runscript.js</strong></p>
  
  <pre><code>var page = require('webpage').create();
  page.viewportSize = { width: 640, height: 480 };
  
  page.open('index.html', function () {
    setTimeout(function() {
      page.render('TheScreenshot.png', { format: "png" });
      phantom.exit();
    }, 666);
  });
  </code></pre>