title: PHP: Color a square depending id and getting data from db
body: <p>I must to create a page filled by n square, these square will be coloured using a colorpicker, then when the data is stored on db I must to get these value and fill in the background color attribure:</p>
  
  <p>I'm using this code:</p>
  
  <pre><code>&lt;?php
      $square=0;
      $sqid=0;
  
      while ($square &lt;= $numSquare) {
  
          $square++;
          $id = $sqid++;
  
          $getExist = $DB_CON -&gt; query("SELECT * FROM square WHERE SQUARE = " . $id);
          $exist = $getExist-&gt;fetch();
  
          if (isset($exist[2])) { $color=$exist[2]; } else { $color=''; }
  
          if (null !== $exist) {
              if ($exist[0] = $id) {
                  print '&lt;div class="square" id="' . $exist[0] . '" style="background-color:' . $color . '"&gt;&lt;/div&gt;';
              }
          } else {
              print '&lt;div class="square" id="' . $id .'"&gt;&lt;/div&gt;';
          }
      }
  ?&gt; 
  </code></pre>
  
  <p>So it search for the row in DB, (eg: row 1 contain color #000000) and put in <code>style="background-color:x"</code> attribute, the problem is that using this code all the square got the background-color set to none even if they mustn't have none. (eg = must to be <code>&lt;div class="square" id="n"&gt;</code> and got <code>&lt;div class="square" id="n" style="background-color:"&gt;</code> ), in addition to this the first square, related to the ID 0 in database doesn't got any color even if must to be #000000.</p>
  
  <p>Thanks to all who can help. </p>