Hi all, I'm a new user to the forums as well as to PHP itself, I can do the general stuff (log in, cookies sessions etc) but I still don't know the syntax well enough to expand into more complex code successfully.
The problem I'm having is that I am coding a VERY basic on-line shop, and I'm trying to get it to sort the results based on what option the user selects from a drop-down box. I get the following error - Parse error: syntax error, unexpected T_VARIABLE in ... on line 65. I was hoping you could take a look at my code and see where I'm going wrong and correct the code or point me in the right direction of a solution(s). There may be many as I know the basic form of the code is correct but as I mentioned I'm still new to PHP syntax.
ANY help would be appreciated as I've tried quite a few combinations ( IF - ELSEIF - ELSE statements etc) and I'm drawing a blank
The code is as follows...
<?php
// Include MySQL class
REQUIRE_ONCE('inc/mysql.class.php');
// Include database connection
REQUIRE_ONCE('inc/global.inc.php');
// Include functions
REQUIRE_ONCE('inc/functions.inc.php');
// Start the session
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<HEAD>
<TITLE> Supplies4Salons
</TITLE>
<LINK rel="stylesheet" href="css/styles.css" />
</HEAD>
<BODY>
<DIV id="shoppingcart">
<H1>Your Shopping Cart</H1>
<?php
ECHO writeShoppingCart();
?>
</DIV>
<DIV id="itemlist">
<H1>Items In Our Store</H1>
<DIV id ="sort">
<SELECT name="sortBy">
<OPTION value="name"sort="1">Name</OPTION>
<OPTION value="priceAsc"sort="2">Price Ascending</OPTION>
<OPTION value="priceDesc"sort="3">Price Descending</OPTION>
<OPTION value="popAsc"sort="4">Popularity Ascending</OPTION>
<OPTION value="popDesc"sort="5">Popularity Descending</OPTION>
</SELECT>
<INPUT type="submit" value="sort" name="submit"><BR /></FORM><BR />
</DIV>
<?php
$sortBy = $_GET["sortBy"];
switch ($sortby)
{
case 1:
{
$sqlExtra = "ORDER BY name ASC";
};break;
case 2:
{
$sqlExtra = "ORDER BY price ASC";
};break;
case 3:
{
$sqlExtra = "ORDER BY price DESC";
};break;
case 4:
{
$sqlExtra = "ORDER BY popularity ASC";
};break;
case 5:
{
$sqlExtra = "ORDER BY popularity DESC";
};break;
}
$sql = "SELECT values FROM products ".$sqlExtra;
$output[] = '<ul>';
WHILE ($row = $result->fetch()) {
$output[] = '<li>"'.$row['title'].'" by '.$row['manufacturer'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>';
}
$output[] = '</ul>';
ECHO join('',$output);
?>
</DIV>
</DIV>
</BODY>
</HTML>
Thanks in advance for any help!