title: Help with a T_ELSE parse error: syntax error
body: <pre><code>&lt;?php
  
  switch($_GET["action"])
  {
  case "add_item":
  {
  AddItem($_GET["ids"], $_GET["qty"]);
  ShowCart();
  break;
  }
  case "update_item":
  {
  UpdateItem($_GET["ids"], $_GET["qty"]);
  ShowCart();
  break;
  }
  case "remove_item":
  {
  RemoveItem($_GET["ids"], $_GET["id"]);
  ShowCart();
  break;
  }
  default:
  {
  ShowCart();
  }
  }
  function AddItem($itemId, $qty){
  
  
  $result = mysql_query("SELECT COUNT(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");
  
  $row = mysql_fetch_row($result);
  $numRows = $row[0];
  
  if($numRows == 0)
  {
  // This item doesn't exist in the users cart,
  // we will add it with an insert query
  
  mysql_query("INSERT INTO cart(cookieId, id, qty) values('" . GetCartId() . "', $itemId, $qty)");
  //printf ("Inserted records: %d\n", mysql_affected_rows());
  
  }
  else
  {
  // This item already exists in the users cart,
  // we will update it instead
   mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");
  
  }
  
  }
  
  function UpdateItem($itemId, $qty)
  {
  
  mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");
  //printf ("Updated records: %d\n", mysql_affected_rows());
  
  }
  
  function RemoveItem($itemId) 
  {
  
  mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");
  }
  echo $ids;
  ?&gt;
  
  &lt;?php 
  function ShowCart()
  
  {
  
  $result = mysql_query("SELECT
                cart.id         cart_id,
                cart.id         cart_id,
                cart.cartId     cartId,
                cart.cookieId   cookie_Id,
                cart.qty        qt_y,                     
                cdkb.id         cdkb_id,
                cdkb.name       name,
                cdkb.image      image,
                cdkb.price      price,
                dkb.id          dkb_id,
                dkb.name        name1, 
                dkb.image       image1,
                dkb.price       price2,
                dbl.product_id  product_id,
            dbl.price       price3,
            dbl.variety     variety,
            dbl.description description                  
      FROM
      cart
  
  
      LEFT OUTER JOIN cdkb
         ON cart.id = cdkb.id    
  
      LEFT OUTER JOIN dkb
         ON cart.id = dkb.id
  
      LEFT OUTER JOIN dbl
         ON dbl.id = dkb.id 
  
  
  WHERE
      cart.cookieId ='" . GetCartId() . "' ' ORDER BY cdkb.name AND dkb.name ASC");?&gt;
  
  &lt;div id="cart"&gt;
  &lt;div id="group"&gt;
  &lt;div id="quantity"&gt;Qty&lt;/div&gt;
  &lt;div id="cartpic"&gt;Pic&lt;/div&gt;
  &lt;div id="product"&gt;Product&lt;/div&gt;
  &lt;div id="cartprice"&gt;Price&lt;/div&gt;
  &lt;div id="remove"&gt;Remove&lt;/div&gt;
  &lt;/div&gt;
  &lt;?php
  
  $totalCost=0;
  foreach($result as $row)
  {  
  if($row['ckb_id']){
  // Increment the total cost of all items
  $totalCost += ($row["qt_y"] * $row["price"]);
  
  ?&gt;
  
  &lt;div id="cart1"&gt;
  &lt;select name="&lt;?php echo $row["cdkb_id"];?&gt;" onChange="UpdateQty(this)"&gt;
  &lt;?php  print($row["cdkb_id"]);?&gt;
  &lt;?php
  
  for($i = 1; $i &lt;= 30; $i++)
  {
  echo "&lt;option ";
  if($row["qt_y"] == $i)
  {
  echo " SELECTED ";
  }
  echo "&gt;" . $i . "&lt;/option&gt;";
  }
  ?&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;div id="cart2"&gt;
  &lt;img src="images/logopic.gif"&lt;?php /*?&gt;&lt;?php echo $row["image"]; ?&gt;&lt;?php */?&gt; alt="we" width="60" height="50" /&gt;
  &lt;/div&gt;
  &lt;div id="cart3"&gt;&lt;p&gt;&lt;?php echo $row["name"]; ?&gt;&lt;/p&gt;&lt;/div&gt;
  
  
  
  &lt;div id="cart4"&gt;&lt;p&gt;
  $&lt;?php echo number_format($row["price"], 2, ".", ","); ?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;div id="cart5"&gt;
  &lt;p&gt;&lt;?php
  printf('&lt;a href="cart.php?action=remove_item&amp;id=%d&amp;ids=%d&amp;register=%s"&gt;Remove&lt;/a&gt;', $_GET['id'], $row['cdkb_id'], $_GET['register']);
  ?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;hr size="1" color="red" &gt;
  
  &lt;script language="JavaScript"&gt;
  
  function UpdateQty(item)
  {
  itemId = item.name;
  newQty = item.options[item.selectedIndex].text;
  
  document.location.href = 'cart.php?action=update_item&amp;id='+itemId+'&amp;qty='+newQty;
  }
  
  &lt;/script&gt;
  
  
  
  
  
  
  &lt;?php
  }
  ?&gt;
  &lt;?php
  else {
  ?&gt;
  &lt;?php // Increment the total cost of all items
  $totalCost += ($row["qt_y"] * $row["price2"]);
  
  ?&gt;
  
  &lt;div id="cart1"&gt;
  &lt;select name="&lt;?php echo $row["dkb_id"];?&gt;" onChange="UpdateQty(this)"&gt;
  &lt;?php  print($row["dkb_id"]);?&gt;
  &lt;?php
  
  for($i = 1; $i &lt;= 30; $i++)
  {
  echo "&lt;option ";
  if($row["qt_y"] == $i)
  {
  echo " SELECTED ";
  }
  echo "&gt;" . $i . "&lt;/option&gt;";
  }
  ?&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;div id="cart2"&gt;
  &lt;img src="images/logopic.gif"&lt;?php /*?&gt;&lt;?php echo $row["image2"]; ?&gt;&lt;?php */?&gt; alt="we" width="60" height="50" /&gt;
  &lt;/div&gt;
  &lt;div id="cart3"&gt;&lt;p&gt;&lt;?php echo $row["name2"]; ?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;?php foreach ($row['dkb_id'] as $variety) {?&gt;
  &lt;div id="cart4"&gt;
     &lt;?php echo"&lt;p&gt;".$variety['variety']. " ~ " . $variety['price3'] . "&lt;/p&gt;" ?&gt;
  &lt;p&gt;$&lt;?php echo number_format($row["price3"], 2, ".", ","); ?&gt;&lt;/p&gt;&lt;/div&gt;
  &lt;?php } ?&gt;
  &lt;div id="cart5"&gt;
  &lt;p&gt;&lt;?php
  printf('&lt;a href="cart.php?action=remove_item&amp;id=%d&amp;ids=%d&amp;register=%s"&gt;Remove&lt;/a&gt;', $_GET['id'], $row['dkb_id'], $_GET['register']);
  ?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;hr size="1" color="red" &gt;
  
  &lt;script language="JavaScript"&gt;
  
  function UpdateQty(item)
  {
  itemId = item.name;
  newQty = item.options[item.selectedIndex].text;
  
  document.location.href = 'cart.php?action=update_item&amp;id='+itemId+'&amp;qty='+newQty;
  }
  
  &lt;/script&gt;
  
  
  
  
  &lt;font face="verdana" size="2" color="black" style="clear:right;"&gt;
  &lt;b&gt;Total: $&lt;?php echo number_format($totalCost, 2, ".", ","); ?&gt;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
  
  
  &lt;?php } ?&gt;
  &lt;?php } ?&gt;
  &lt;div id="shopping"&gt;
  &lt;a href=&lt;?php echo "exa2.php?id=".intval($id).  '&amp;register='. $_GET['register']. ""?&gt;&gt; Keep Shopping&lt;/a&gt;&lt;/div&gt;
  &lt;?php /*?&gt;&lt;tr&gt;
  &lt;td colspan="4"&gt;
  &lt;font face="verdana" size="1" color="black"&gt;
  &lt;a href=&lt;?php echo "cart.php?id=".intval($id).  '&amp;register='. $_GET['register']. ""?&gt;&gt;Your Shopping Cart&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;/tr&gt;&lt;?php */?&gt;
  
  &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/table&gt;
  </code></pre>
  
  <p>Hi For those who has commented on 
  <a href="https://stackoverflow.com/questions/2298885/help-with-a-unexpected-t-else">Help with a unexpected T_ELSE</a>
  this is the subsequent thread I couldn't post int he other account because accessibility issues.</p>
  
  <p>In the code above below the query there will be an if and else statement sequence that is causing a parse errror: syntax error, as it fallows Parse error: syntax error, unexpected T_ELSE. Look at the if and else statment design and what's possiblly causing this error.</p>
  
  <pre><code>if {
    for (blabla) {
      if {
  
      }// end of if statement inside the for loop
  
    } //end of for loop.
  
  } end of if statement 
  else{ // line 379
  
  
  }// end of else statement
  </code></pre>
  
  <p>What I believe is causing the T_ELSE syntax error above as I said in the last post is the if statement inside the for loop. Php believes that the else statement is working together with the if statement inside the for loop and what I want is the if statement outside the for loop work together with the else statement. The error looks like this:</p>
  
  <p>PS everything that possibly causing the parse error is below the query. thanks.</p>
  
  <p>The INTENDED DISPLAY in between the if and else would look like </p>
  
  <pre><code>foreach($result as $row)
      {  
      if (table cdkb) { 
        [1]qyt         image      name          price        remove
           1            ---       marina        $18.90        remove?    
           }end of if statement
      Else table dkb {
         1]qyt            Image         Name             Price                  Remove
           1               ---         marina         Small Tray  $18.90        remove? 
                                                      Medium Tray $30.24
                                                      Large Tray  $35.90
                        } // end of else statement
  
                        }//end of while loop
  </code></pre>
  
  <p>This is the array structure behind the INTENDED display!</p>
  
  <pre><code>&lt;?php
  $result = array(
          '0' =&gt; array('cdkb_id' =&gt; 'id 1',
              'image' =&gt; 'img 1',
              'name' =&gt; 'name 1',
              'price' =&gt; 'price 1'
              ),
          '1' =&gt; array('image1' =&gt; 'img 2',
              'name1' =&gt; 'name 2',
              'dkb_id' =&gt; array('0' =&gt; array('variety' =&gt; 'variety 2-1',
                           'price3' =&gt; 'price 2-1'
                          ),
                      '1' =&gt; array('variety' =&gt; 'variety 2-2',
                           'price3' =&gt; 'price 2-2'
                          ),
                      '2' =&gt; array('variety' =&gt; 'variety 2-3',
                           'price3' =&gt; 'price 2-3'
                          )
                      )
              ),
          '2' =&gt; array('cdkb_id' =&gt; 'id 3',
              'image' =&gt; 'img 3',
              'name' =&gt; 'name 3',
              'price' =&gt; 'price 3'
              ),
          '3' =&gt; array('image1' =&gt; 'img 4',
              'name1' =&gt; 'name 4',
              'dkb_id' =&gt; array('0' =&gt; array('variety' =&gt; 'variety 4-1',
                           'price3' =&gt; 'price 4-1'
                          ),
                      '1' =&gt; array('variety' =&gt; 'variety 4-2',
                           'price3' =&gt; 'price 4-2'
                          ),
                      '2' =&gt; array('variety' =&gt; 'variety 4-3',
                           'price3' =&gt; 'price 4-3'
                          )
  </code></pre>
  
  <p>The only thing on the way is the T_ELSE because there is an if in between the if and else statement inside the for loop....</p>
  
  <p>Thank.</p>