title: How do I save individual MySQL results to PHP variables?
body: <p>I have this database that I've been working on, and I'm at the point where I'm trying to tie everything together and start integrating the information from my database tables into actual web pages. What I'm trying to do is to query the database for specific answers which I want to save to PHP variables so I can perform a simple <code>&lt;?php echo $variable; ?&gt;</code> throughout my webpage. However I can't seem to figure out how to do that. </p>
  
  <p>Here's a sample of what I've been trying. </p>
  
  <p><strong>SQL</strong> </p>
  
  <pre><code>$Name = "John Smith";
  
  $Nickname = $db-&gt;query('SELECT `Nickname` FROM `Profiles` WHERE `Name` =' . $Name);
  $country = $db-&gt;query('Select `Country` from `Profiles` Where `Name` =' . $Name);
  </code></pre>
  
  <p><strong>PHP/HTML</strong></p>
  
  <pre><code>&lt;div&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;th colspan ="2"&gt;&lt;?php echo $Name; ?&gt;&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Country&lt;/td&gt;&lt;td&gt;&lt;?php echo $country; ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Nickname&lt;/td&gt;&lt;td&gt;&lt;?php echo $Nickname; ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This isn't EXACTLY what I've been doing, the table(s) I'm trying to plug this information into is/are far more complicated, which is why if at all possible, I'd like to avoid using the normal method of returning MySQL queries:</p>
  
  <p><strong>Code I'd like to avoid if possible</strong></p>
  
  <pre><code>&lt;?php
  while ($rows = $country-&gt;fetch()){
  echo ['Country'];
  }
  ?&gt;
  </code></pre>
  
  <p>In the event that the above code is still by far the simplest way to return any/all query results, I just have one question: <strong>Is it possible to nest different</strong> <code>while ($rows = $variable-&gt;fetch())</code> <strong>statements within each other?</strong> Because my table has information from different database tables somewhat scattered throughout it and there are a couple of places where I would NEED to nest the WHILE statement. Would it work?</p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>So I've tried a couple of suggestions. First, I changed my SQL syntax for the $Name so that it will work in the SQL query. </p>
  
  <pre><code>`WHERE `Name` ="' . $Name . '"');`
  </code></pre>
  
  <p>So now that's working. But I've tried the other 2 suggestions and both are breaking my code (the page won't load). </p>
  
  <p>Also, no one's answered my question about being able to nest <code>While()</code> Statements. </p>