title: PHP If statement, suitable?
body: <p>I'm working on a small university assignment to build a simple e-commerce engine using PHP for a website. </p>
  
  <p>I currently have the following script setup to display products within a category, all of which are retrieved from a MySQL database. </p>
  
  <pre><code>http://example.com/category.php?id=2
  </code></pre>
  
  <p>The problem I am currently having is that for each product displayed the script is simply echoing each one side by side into a new table entry. This is causing them to go across the page rather than vertically. </p>
  
  <p>What would be the best way to alter this code to have for example a maximum of three products per row? An If loop or something along those lines? Would appreciate the support!</p>
  
  <pre><code>&lt;?php
  
  //Create Session
     session_start();
  
  //Connect to database
     include "conn.php";
  
  //Retrieve Header
     include "header.php";
  
  //Get Category ID 
  if (isset($_GET['id'])){
      $CategoryID = $_GET['id'];
  
  //QUERY collects product name, and product ID.
      $q="SELECT ProductID, ProductName, Price,img FROM Products WHERE CategoryID=$CategoryID";
  
  //QUERY collects Product Category descriptions
      $d="SELECT `Desc` FROM ProductCategories WHERE CategoryID=$CategoryID";
  
  //retrive and execute SQL query results and save into a variable
      $result = mysqli_query($_SESSION['conn'],$q);
      $result2 = mysqli_query($_SESSION['conn'],$d) or die(mysql_error());
  
  //Retrieve Product Category Description
      echo "&lt;div&gt;";
      while ($myResult = mysqli_fetch_row($result2)){ //Create an array
          echo "&lt;p&gt;".$myResult[0]."&lt;/p&gt;";
      }
      echo "&lt;/div&gt;";
  
  //Retrieve Products in category
      echo "&lt;div align='center'&gt;&lt;table border='1px' bordercolor='#000000' width='200px'&gt;&lt;tr&gt;"; //Define table, row and div containing each product
  
      while ($row = mysqli_fetch_row($result)){ //Create an array
  
          echo "&lt;td&gt;"; //Create table cell
          echo "&lt;p&gt;&lt;img src=".$row[3]."&gt;&lt;/p&gt;"; //product image small (250x250 Pixels)
          echo "&lt;p  align='center'&gt;&lt;a href='product.php?id=".$row[0]."'&gt;".$row[1]." &lt;/a&gt;&lt;/p&gt;"; //Product ID Link and Name
          echo "&lt;p align='center'&gt;&amp;#163; ".$row[2]."&lt;/p&gt;";
          echo "&lt;/td&gt;"; //Close table cell
      }
      echo "&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;";//Close table, div and row
      mysqli_free_result($result);
  }
  
  // Retireve Footer
  include "footer.php";
  ?&gt;
  </code></pre>
  
  <p>I am new when it comes to programming of any kind, so would appreciate patience/any support you could give me. Also I am aware of the SQL injection problem and will fix this at a later date. </p>