I am a Newbie To PHP!!
I used maestro php myqsl to crate the code below..
I am trying to change the query to include a where statment:
"where Product_Category = Acoustic treatment"
everytime i edit it i get a syntax Error!!
please can you help?
Thanks in advance
<?php session_start();
if (isset($_GET["getimage"]))
{
$conn = connect();
getimage(@$_GET["getimage"], @$_GET["field"]);
exit;
}
?>
<html>
<head>
<title>sounscou_Datapoint -- prod_listing</title>
<meta name="generator" http-equiv="content-type" content="text/html">
<style type="text/css">
body {
background-color: #FFFFFF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
.bd {
background-color: #FFFFFF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
.tbl {
background-color: #FFFFFF;
}
a:link {
background-color: #FFFFFF01;
color: #0000CD;
font-family: Arial;
font-size: 12px;
}
a:active {
background-color: #FFFFFF01;
color: #0000FF;
font-family: Arial;
font-size: 12px;
}
a:visited {
background-color: #FFFFFF01;
color: #800080;
font-family: Arial;
font-size: 12px;
font-style: italic;
}
.hr {
background-color: #000000;
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
a.hr:link {
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
a.hr:active {
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
a.hr:visited {
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
.dr {
background-color: #FFFFFF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
.sr {
background-color: #F3F3F3;
color: #000000;
font-family: Arial;
font-size: 12px;
font-weight: bold;
}
</style>
</head>
<body>
<p>
<a href="http://localhost/sounscou_Datapoint/prod_listing.php?a=view&recid=77">http://localhost/sounscou_Datapoint/prod_listing.php?a=view&recid=77</a>
<?php
$conn = connect();
$showrecs = 10;
$pagerange = 10;
$a = @$_GET["a"];
$recid = @$_GET["recid"];
$page = @$_GET["page"];
if (!isset($page)) $page = 1;
switch ($a) {
case "view":
viewrec($recid);
break;
default:
select();
break;
}
mysql_close($conn);
?>
</p>
<p>
<?php function select()
{
global $a;
global $showrecs;
global $page;
$res = sql_select();
$count = sql_getrecordcount();
if ($count % $showrecs != 0) {
$pagecount = intval($count / $showrecs) + 1;
}
else {
$pagecount = intval($count / $showrecs);
}
$startrec = $showrecs * ($page - 1);
if ($startrec < $count) {mysql_data_seek($res, $startrec);}
$reccount = min($showrecs * $page, $count);
?>
</p>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><div align="center">Complete Product Listing</div></td>
</tr>
<tr><td>Records shown <?php echo $startrec + 1 ?> - <?php echo $reccount ?> of <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<div align="center">
<?php showpagenav($page, $pagecount); ?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<?php if ($page > 1) { ?>
<td><a href="prod_listing.php?page=<?php echo $page - 1 ?>"><< Prev</a> </td>
<?php } ?>
<?php
global $pagerange;
if ($pagecount > 1) {
if ($pagecount % $pagerange != 0) {
$rangecount = intval($pagecount / $pagerange) + 1;
}
else {
$rangecount = intval($pagecount / $pagerange);
}
for ($i = 1; $i < $rangecount + 1; $i++) {
$startpage = (($i - 1) * $pagerange) + 1;
$count = min($i * $pagerange, $pagecount);
if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
for ($j = $startpage; $j < $count + 1; $j++) {
if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="prod_listing.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="prod_listing.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td> <a href="prod_listing.php?page=<?php echo $page + 1 ?>">Next >></a> </td>
<?php } ?>
</tr>
</table>
<table class="tbl" border="0" cellspacing="1" cellpadding="6"width="90%">
<?php
for ($i = $startrec; $i < $reccount; $i++)
{
$row = mysql_fetch_assoc($res);
$style = "dr";
if ($i % 2 != 0) {
$style = "sr";
}
?>
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="4%" rowspan="2" class="<?php echo $style ?>"><div align="center"><font face="Verdana, Arial, Helvetica, sans-serif"><a href="prod_listing.php?a=view&recid=<?php echo $i ?>"><?php echo outimage($i, "Product_Picture", "", "", "") ?></a></font></div></td>
<td width="22%" height="30" class="<?php echo $style ?>"><div align="center">
<p><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"><?php echo htmlspecialchars($row["Product_Name"]) ?></font></p>
</div></td>
<td width="39%" rowspan="2" class="<?php echo $style ?>"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"><?php echo htmlspecialchars($row["Product_Description"]) ?><a href="prod_listing.php?a=view&recid=<?php echo $i ?>">View</a></font></td>
<td width="6%" rowspan="2" class="<?php echo $style ?>"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"><a href="prod_listing.php?a=view&recid=<?php echo $i ?>"><img src="images/info.new.norm.gif" alt="view info" name="Info" width="34" height="31" border="0"></a></font></td>
<td width="18%" rowspan="2" class="<?php echo $style ?>"><div align="center"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> <font color="#0000FF"><?php echo htmlspecialchars($row["Product_Category"]) ?> </font><font color="#000000"><strong>></strong></font><font color="#0099FF"> <?php echo htmlspecialchars($row["Product_subcat"]) ?> </font></font></div></td>
<td width="11%" rowspan="2" class="<?php echo $style ?>"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> <a href="<?php echo htmlspecialchars($row["Product_Cart"]) ?>"><img src="images/add.new.norm.gif" alt="add to basket" name="Info" width="85" height="31" border="0"></a></font></td>
</tr>
<tr>
<td height="30" class="<?php echo $style ?>"><div align="center"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"><strong>£<?php echo htmlspecialchars($row["Product_price"]) ?></strong></font></div></td>
</tr>
<?php
}
mysql_free_result($res);
?>
</table>
<?php } ?>
</div>
<p align="center">
<?php function showrow($row, $recid)
{
?>
</p>
<table width="500" height="183" border="0" align="center" cellpadding="4" cellspacing="1" class="bd">
<!--DWLayoutTable-->
<tr>
<td width="705" height="26" valign="top"><div align="center"><font size="4" face="Verdana, Arial, Helvetica, sans-serif"><?php echo htmlspecialchars($row["Product_Name"]) ?></font></div></td>
<td width="102" rowspan="2" align="center" valign="middle"><?php echo outimage($recid, "Product_Picture", "product picture", "", "") ?>
<p><strong><font size="3" face="Verdana, Arial, Helvetica, sans-serif">£<?php echo htmlspecialchars($row["Product_price"]) ?></font></strong></p></td>
</tr>
<tr>
<td height="64" valign="top"><font size="3"><strong><?php echo htmlspecialchars("Product Description")." " ?> : </strong></font>
<blockquote>
<p><?php echo htmlspecialchars($row["Product_Description"]) ?></p>
</blockquote></td>
</tr>
<tr>
<td height="23"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong><?php echo htmlspecialchars("Product_Features")." " ?> :</strong> </font>
<blockquote>
<p><?php echo htmlspecialchars($row["Product_Features"]) ?></p>
</blockquote></td>
<td align="center" valign="middle"><a href="<?php echo htmlspecialchars($row["Product_Pdf"]) ?>"><img src="../images/pdf_icon.gif" alt="" width="53" height="57" border="0"></a></td>
</tr>
<tr>
<td height="23" colspan="2"><blockquote>
<p align="center"><strong><font size="+6"><a href="<?php echo htmlspecialchars($row["Product_Cart"]) ?>">cart</a></font></strong></p>
</blockquote></td>
</tr>
</table>
<?php } ?>
<?php function showpagenav($page, $pagecount)
{
?>
<?php } ?>
<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="prod_listing.php">Index Page</a></td>
<?php if ($recid > 0) { ?>
<td><a href="prod_listing.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Prior Record</a></td>
<?php } if ($recid < $count - 1) { ?>
<td><a href="prod_listing.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Next Record</a></td>
<?php } ?>
</tr>
</table>
<hr size="1" noshade>
<p>
<?php } ?>
<?php function viewrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<?php
mysql_free_result($res);
} ?>
<?php function connect()
{
$conn = mysql_connect("host", "username", "password");
mysql_select_db("sounscou_Datapoint");
return $conn;
}
function sql_select()
{
global $conn;
$sql = "SELECT `Product_Name`, `Product_Description`, `Product_Picture`, `Product_price`, `Product_Category`, `Product_Pdf`, `Product_Cart`, `Product_Features`, `Product_subcat`, `Key` FROM `prod_listing`";
$res = mysql_query($sql, $conn) or die(mysql_error());
return $res;
}
function sql_getrecordcount()
{
global $conn;
$sql = "SELECT COUNT(*) FROM `prod_listing`";
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res);
reset($row);
return current($row);
}function get_file_content_as_sql($fieldname)
{
global $_FILES;
$sql = "";
if (!empty($_FILES))
$sql=mysql_escape_string(file_get_contents(@$_FILES['x_'.$fieldname]['tmp_name']));
if ($sql == '')
$sql = 'null';
else
$sql = "'".$sql."'";
return $sql;
}
function get_file_content_as_sql_for_update($fieldname)
{
global $_POST;
$sql = "`$fieldname` = `$fieldname`";
if (isset($_POST["a_".$fieldname]))
{
switch ($_POST["a_".$fieldname]) {
//remove
case "2":
$sql = "`$fieldname`= null";
break;
//replace
case "3":
$sql = "`$fieldname`=" .get_file_content_as_sql($fieldname);
break;
}
}
return $sql;
}
function outimage($recid, $field, $alt, $width, $height)
{
$res = "<img src=\"prod_listing.php?getimage=$recid&field=$field\" border=0 alt=\"$alt\"";
if ($width <> '')
$res = $res." width=\"$width\"";
if ($height <> '')
$res = $res." height=\"$height\"";
$res = $res.">";
return $res;
}
function getimage($recid, $field)
{
$res = sql_select();
mysql_data_seek($res, $recid);;
$row = mysql_fetch_assoc($res);
echo $row[$field];
}
?>
</p>
</body>
</html>