1. Extracts values from a database
2. Displays them as a color options menu
3. When an option is selected, the picture changes and the selection on the drop-down menu on the bottom of the screen changes.
For instance, clicking a Black and White image icon changes the big glass picture to a Black and White shade, and the color selected to be ordered is Black and White.
What I want to do is make an exception for every color option that starts with the string "snapshot". Upon detecting this string, the color is not shown in the palette but in a second list of thumbnails. The second list can show larger images upon clicking just like the first, but will not be an option on the drop-down menu on the bottom. Where do I put the conditional statements to make this happen?
Here is the PHP code that I have so far. The two tables are labeled. I trimmed the code down for your convenience so it may not work if you tested the code as-is.
The normal color pallete code starts around line 121 and the alternate view code (basically a copy) starts around 166.
<?
ini_set('display_errors',1);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors','Off');
include 'db.php';
if (!isset($_POST['action']))
{
//If not isset -> set with dumy value
$_POST['action'] = "undefine";
}
session_start();
header("Cache-control: private");
//add to cart
if($_POST['action']=='add'){
if(!isset($_SESSION['cart'])){
$_SESSION['cart']=array();
}
$item=$_POST['id'] . '||';
$item.=$_POST['glass'] . '||';
$item.=$_POST['finishes'] . '||';
$item.=$_POST['stocks'] . '||';
$item.=$_POST['cord_colors'] . '||';
$item.=$_POST['ceiling'] . '||';
$item.=$_POST['glass_shape'] . '||';
$item.=$_POST['leafs'] . '||';
$item.=$_POST['ceil_cap'];
array_push($_SESSION['cart'],$item);
header("Location: viewcart2.php?back=" . urlencode("pro.php?id=" . $_POST['id']));
exit;
}
?>
</td></tr></table>
<!-- end #header --></div>
<?
/* Display categories */
$query = "SELECT id,category,description from categories where id!=11 and deleted=0 order by category";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$last=0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if($last>0){
?>
<!-- | -->
<?
}
?>
<!--<a href="cat.php?id=<?= $line['id'] ?>" class="sub"><?= $line['category']
?></a>-->
<?
if($_GET['id']==$line['id'] || $last==0){
$description=stripslashes($line['description']);
$title=stripslashes($line['category']);
$last=$line['id'];
}
}
if(isset($_GET['id'])){
$last=$_GET['id'];
}
mysql_free_result($result);
//get product details and convert them into local variables
$query = "SELECT * from products where deleted=0 and id=" . $_GET['id'];
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$name = stripslashes($line['name']);
$description = stripslashes($line['description']);
$retail = stripslashes($line['retail']);
$price = stripslashes($line['price']);
$bulb = stripslashes($line['bulb']);
$redirect = stripslashes($line['redirect']);
$ceiling = stripslashes($line['ceiling']);
$dims = stripslashes($line['dims']);
$static = stripslashes($line['static']);
}
mysql_free_result($result);
//determining if product has signature or radiance glass, also sets values for cap n pole image
$colorsetname = "Signature";
if ((isset($name))&&((substr($name,14,8)=="Radiance")||(substr($name,0,8)=="Radiance")))
{$viewcol=5;
$colorsetname = "Radiance";}
else {$viewcol=6;}
$ispendant = 16;
$redirviewcol = ($viewcol+999);
?>
<table height="530" width="890" border="0" cellpadding="4" cellspacing="0">
<tr>
<td width="560" height="371" align="middle" valign="middle">
<img name="mainimg" id="mainimg" src="<?
//get main image
$query = "SELECT * from glass where deleted=0 and pid=" . $_GET['id'] . " order by color limit 1";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo $line['url'];
}
mysql_free_result($result);
?>" >
<!-- width="263" height="353" -->
</td><? if(($_GET['id']==1004)||($_GET['id']==1005))
{echo '</tr><tr>';}?>
<td valign="middle" align ="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" align="center">
<? if($_GET['id']!=14){ ?>
<table width="239" border="0" cellspacing="0" cellpadding="0">
<?
$narrows=3;
if(($_GET['id']==1004)||($_GET['id']==1005))
{$narrows=5;}
//This is the normal color pallete menu
$query = "SELECT * from glass where deleted=0 and pid=" . $_GET['id'] . " order by color";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if(mysql_num_rows($result)>1){
echo '<tr valign="top">
<td colspan="4"><span class="sub">Colors</span>
<span class="small">(click swatch to see item in that color glass)</span>';
if ($narrows==3)
{echo '<br />Click to order a <a href="pro.php?id='.$redirviewcol.'">'.$colorsetname.'</a> glass sample!</a></td></tr>';}
else {echo'</tr>';}
echo '<tr>';
$cnt=0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<td><img src="' . $line['color_url'] . '" width="120" height="61" hspace="4" vspace="4"
border="0" onclick="change_glass(' . "'" . $line['color'] . "'" . ');document.mainimg.src=' . "'" . $line['url'] . "'" . '">
</td>';
$cnt++;
$lookupcolor.=" if(col=='" . $line['color'] . "'){ return '" . $line['url'] . "'; }\n";
if($cnt % $narrows == 0){
echo '</tr><tr>';
}
}
echo '</tr>';
}
mysql_free_result($result);
$query = "SELECT * from finishes where deleted=0 and pid=" . $_GET['id'] . " order by finish";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
?>
</table></td></tr><tr><td align="center">
<?PHP
} //end id!=14 ?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" align="center">
<? if($_GET['id']!=14){ ?>
<table width="239" border="0" cellspacing="0" cellpadding="0">
<?
$narrows=5;
//This is for the alternate or installed views of the product in a separate table
$query = "SELECT * from glass where deleted=0 and pid=" . $_GET['id'] . " order by color";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if(mysql_num_rows($result)>1){
echo '<tr valign="top">
<td colspan="4"><span class="sub">Installed or Alternate Views</span>';}
else {echo'</tr>';}
echo '<tr>';
$cnt=0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<td><img src="' . $line['color_url'] . '" width="120" height="61" hspace="4" vspace="4"
border="0" onclick="change_glass(' . "'" . $line['color'] . "'" . ');document.mainimg.src=' . "'" . $line['url'] . "'" . '">
</td>';
$cnt++;
$lookupcolor.=" if(col=='" . $line['color'] . "'){ return '" . $line['url'] . "'; }\n";
if($cnt % $narrows == 0){
echo '</tr><tr>';
}
}
echo '</tr>';
}
mysql_free_result($result);
$query = "SELECT * from finishes where deleted=0 and pid=" . $_GET['id'] . " order by finish";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
?>
</table></td></tr><tr><td align="center">
</td>
</tr>
</tr>
<tr>
<td height="77" colspan="2" valign="middle" border="0">
<br /><a href="javascript:;"> </a></span>
<b>
<!-- Product description -->
<?= $name ?></b><br><br>
<?= $description; ?>
<br />
<br />
<?= $redirect; ?>
<br />
<br />
<?=
$nostr = "";
$showdims = substr($dims, 0, 70);
echo $showdims;
?>
<br />
<br />
<?= $bulb; ?>
<div id="notify_price"></div>
</td></td>
<tr>
<td align="center" colspan="2"><form name="form1" method="post" action="pro.php">
<input type="hidden" name="action" value="add">
<input type="hidden" name="id" value="<?= $_GET['id']; ?>">
<table border="0" cellspacing="10" cellpadding="0">
<tr>
<?
$header_number=1;
//get glass color if id not equal to 14
if($_GET['id']!=14){
$query = "SELECT * from glass where deleted=0 and pid=" . $_GET['id'] . " order by color";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if(mysql_num_rows($result)>1){
echo '<td valign=top style="height: 75"><a href="javascript:void(viewer'.$viewcol.'.show(0))" style="text-decoration:none"><img src="images/Circle' . $header_number . '.png" class="nob"> <img src="images/GlassColor.png"></a><br /><select name="glass" onChange="document.mainimg.src=lookupcolor(document.form1.glass.value)">';
$header_number++;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<option value="' . $line['color'] . '">' . $line['color'] . '</option>';
}
echo '</select></td>';
}
mysql_free_result($result);
}//end id!=14
?>
Thanks for reading!


Sign In
Create Account


Back to top









