title: Fetching and echoing results with php
body: <p>I'm having an issue displaying the results of query. The weird thing is, all of the results are being obtained and only one is not. I'm at a complete loss.</p>
  
  <p>I'm going to describe, to the best of my knowledge, how this code is supposed to work. I built it from a tutorial. </p>
  
  <p>In "listProducts.php" all the products in the database are listed in a table. </p>
  
  <pre><code>&lt;table id="productTable"&gt;
    &lt;tr&gt;
      &lt;th&gt;UPC&lt;/th&gt;
      &lt;th&gt;Title&lt;/th&gt;
      &lt;th&gt;Thumb&lt;/th&gt;
      &lt;th&gt;Price&lt;/th&gt;
      &lt;th&gt;Stock&lt;/th&gt;
      &lt;th&gt;Lead Time&lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
    &lt;/tr&gt;
  
  &lt;?php foreach ( $results['products'] as $product ) { 
  
    list($week, $day) = explode("|", $product-&gt;lead);
    echo htmlspecialchars($product-&gt;lead);
  ?&gt;
  
    &lt;tr onclick="location='products.php?action=editProduct&amp;amp;productId=&lt;?php echo $product-&gt;id?&gt;'"&gt;
      &lt;td&gt;&lt;img src="../&lt;?php echo $product-&gt;thumb ?&gt;"/&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo htmlspecialchars($product-&gt;upc)?&gt;&lt;/td&gt;        
      &lt;td&gt;&lt;?php echo htmlspecialchars($product-&gt;title)?&gt;&lt;/td&gt;  
      &lt;td style="text-align:right;"&gt;$&lt;?php echo number_format($product-&gt;price, 2 )?&gt;&lt;/td&gt;
      &lt;td style="text-align:right;"&gt;&lt;?php echo number_format($product-&gt;stock, 0)?&gt;&lt;/td&gt;
      &lt;td style="text-align:right;"&gt;&lt;? echo $week.'|'.$day;?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;button &gt;Edit&lt;/button&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
  &lt;? } ?&gt;
  
  &lt;/table&gt;
  </code></pre>
  
  <p>The problem is lead, which exists in the database as lead, is not being or has not been fetched and therefore not being exploded and is therefore not being echoed as week and day.</p>
  
  <p>Even if, for testing purposes, I echo just lead, i get nothing.</p>
  
  <pre><code>&lt;? echo htmlspecialchars($products-&gt;lead)?&gt;
  </code></pre>
  
  <p>There is a listProducts() function and some class junk that i did not come up with, but I have thoroughly manipulated to my own ends so I'm fairly confident that they should work. But, I'll post them anyway.</p>
  
  <pre><code>function listProducts() {
    $results = array();
    $data = Product::getList();
    $results['products'] = $data['results'];
    $results['totalRows'] = $data['totalRows'];
    $results['pageTitle'] = "All Products";
  
    if ( isset( $_GET['error'] ) ) {
      if ( $_GET['error'] == "productNotFound" ) $results['errorMessage'] = "Error: Product not found.";
    }
  
    if ( isset( $_GET['status'] ) ) {
      if ( $_GET['status'] == "changesSaved" ) $results['statusMessage'] = "Your changes have been saved.";
      if ( $_GET['status'] == "productDeleted" ) $results['statusMessage'] = "Product deleted.";
    }
  
    require( TEMPLATE_PATH . "/admin/listProducts.php" );
  }
  </code></pre>
  
  <p>And here is the parts of the product class that i think deal with displaying the list... cus it says get list.</p>
  
  <pre><code>public static function getList( $numRows=100, $order="title DESC" ) {
      $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
      $sql = "SELECT SQL_CALC_FOUND_ROWS *, id FROM products
              ORDER BY " . $order . " LIMIT :numRows";
  
      $st = $conn-&gt;prepare( $sql );
      $st-&gt;bindValue( ":numRows", $numRows, PDO::PARAM_INT );
      $st-&gt;execute();
      $list = array();
  
      while ( $row = $st-&gt;fetch() ) {
        $product = new Product( $row );
        $list[] = $product;
      }
  
      // Now get the total number of products that matched the criteria
      $sql = "SELECT FOUND_ROWS() AS totalRows";
      $totalRows = $conn-&gt;query( $sql )-&gt;fetch();
      $conn = null;
      return ( array ( "results" =&gt; $list, "totalRows" =&gt; $totalRows[0] ) );
    }
  </code></pre>
  
  <p>and some constructors and variables. I don't know if they are necessary or not</p>
  
  <pre><code>public $id = null;
  public $upc = null;
  public $title = null;
  public $thumb = null;
  public $description = null;
  public $price = null;
  public $stock = null;
  public $lead = null;
  
  public function __construct( $data=array() ) {
  if ( isset( $data['id'] ) ) $this-&gt;id = (int) $data['id'];
  if ( isset( $data['upc'] ) ) $this-&gt;upc = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['upc'] );
  if ( isset( $data['title'] ) ) $this-&gt;title = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['title'] );
  if ( isset( $data['thumb'] ) ) $this-&gt;thumb = $data['thumb'];
  if ( isset( $data['description'] ) ) $this-&gt;description = $data['description'];
  if ( isset( $data['price'] ) ) $this-&gt;price = $data['price'];
  if ( isset( $data['stock'] ) ) $this-&gt;stock = (int) $data['stock'];
  if ( isset( $data['week'] ) &amp;&amp; isset( $data['day'] ) ) $this-&gt;lead = $data['week']."|".$data['day'];
  }
  </code></pre>