title: How to style PHP output?
body: <p>I am learning php and made a simple application to save peoples names to a database then pull all the saved names into a list lower down on the page. </p>
  
  <p>this is the code that is getting the names: <code>echo "&lt;div class=\"results\"&gt; $row[Name] &lt;/div&gt;";</code></p>
  
  <p>I put a div with the class of results so that I could style it. At this point all I wanted to do was center the results. After styling it with css to be centered, looking at the page source each name that was echo'ed has a div around it with the class of results. They are all centered like I wanted which is good but this does not seem like the best way to do it because there will be a new div created for every new name in the database (right now there are 18 divs. Way too many!).I was hoping only one div would be created but I was obviously wrong about that. </p>
  
  <p>So, is it possible to pre-create a div in the html markup with nothing in and echo the names into the div? Or do you think there would be a way to make it all output at once so it was all within the one div?</p>
  
  <p>Here is the rest of the code so you get an idea of whats happening: </p>
  
  <pre><code>&lt;?php 
  $connect = mysql_connect("localhost","user","0123");
  if(!$connect){
      die("Failed to connect: " . mysql_error());
  }
  
  if(!mysql_select_db("Test")) {
      die("Failed to select database: " . mysql_error());
  }
  
  $results = mysql_query("SELECT * FROM Friends");
  
  while($row = mysql_fetch_array($results)){
      echo "&lt;div class=\"results\"&gt; $row[Name] &lt;/div&gt;";
  }
  
  if ($_POST[name] !="") { $sql="INSERT INTO Friends 
  (name) VALUES('$_POST[name]')";
  
  if (!mysql_query($sql,$connect))
    {
    die('Error: ' . mysql_error());
    }
  echo "&lt;div id=\"added\"&gt; $_POST[name] added to the database &lt;/div&gt;";
  }
  else die("")
  
  ?&gt;
  </code></pre>