Image

Imagegwynn_aaron wrote in Imagephp

More PHP help is needed

Continuing the request for help from my previous post I have a new question (my thanks to Imagecarefreespirit who helped me to solve that one).

Looking at this page I am trying to something else. The part which is working is using the 'products' table to make the navigation (light blue links) work. The thing I am trying to add to this page now is the body information which pulls from the 'brands' table. I added in code which I thought would make this happen (bolded code), but it did not.

products.php specifies which brand should be displayed in the sub-navigation of products_displayBrand.php by passing the 'product_brand' variable in the URL which it got from the 'products' table. But the information about the brand is contained in the separate 'brands' table, and I'm not sure how to make the variable from the 'products' table in the URL pull forth the proper record from the 'brands' table. Frankly I'm just confused and not sure how to proceed.

<?
$section = "products_sunshinepro_mix";
$name = "products";
$title = "Products";
include "_formatting.php";
?>

<?
// Start session
session_start();
session_register('valid');
$product_brand=$_GET['product_brand'];

// Define variables
$db_host = "localhost";
$db_user = "********";
$db_pass = "********";
$db_name = "sungroDB";
$table_1 = "brands";
$table_2 = "products";
$connection = @mysql_connect($db_host, $db_user, $db_pass) or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
?>

<?
// Define variables
$sql2 = "SELECT product_id, product_name, product_brand FROM $table_2 WHERE product_brand = '" . $_GET['product_brand'] . "' ORDER BY product_name";
$result2 = @mysql_query($sql2,$connection) or die("Couldn't execute query.");
$products_display = "<div class=\"side_nav_sub\">";

// Start the while loop
while ($row2 = mysql_fetch_array($result2)) {
$product_id = $row2['product_id'];
$product_name = $row2['product_name'];
$product_brand = $row2['product_brand'];
$products_display .= "<a class=\"side_nav_sub\" href=\"products_displayProduct.php?product_id=$product_id\">$product_name</a>";
}

$products_display .= "</div>";
?>

<?
// Check for validity of value of brand
$chk_brand = "SELECT product_brand FROM $table_2 WHERE product_brand = '$product_brand'";
$chk_brand_res = @mysql_query($chk_brand, $connection) or die("Couldn't execute query.");
$chk_brand_num = mysql_num_rows($chk_brand_res);

// Deal with results of validation of id
if ($chk_brand_num == "0") {
header("Location: index.php");
exit;
} else {
$sql = "
SELECT brand_id, brand_name, brand_description, brand_image
FROM $table_1
WHERE brand_id = '$brand_id' || brand_name = '" . $_GET['brand_name'] . "'
";
$result = @mysql_query($sql, $connection) or die("Couldn't execute query.");
}
// WHERE category = '" . $_GET['category'] . "'

// Start the while loop
while ($row = mysql_fetch_array($result)) {
$brand_id = $row['brand_id'];
$brand_name = $row['brand_name'];
$brand_description = $row['brand_description'];
$brand_image = $row['brand_image'];
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Sun Gro Horticulture | <? echo "$title"; ?> | <? echo "$product_brand"; ?></title>

<? echo "$incMeta"; ?>

<link rel="Stylesheet" href="style.css" type="text/css" />

<? echo "$incJavascript"; ?>

</head>
<body id="body">
<div align="center">

<? echo "$incHeader"; ?>

<? echo "$incNavigation"; ?>

<? echo "$incBodyStart"; ?>

<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="body_left" width="170" align="left" valign="top">
<div class="side_nav">
<a class="side_nav" href="products_displayBrand.php?product_brand=Sunshine Professional Growing Mixes">Sunshine Professional Growing Mixes</a>
<? echo "$products_display"; ?>
<a class="side_nav" href="products_displayBrand.php?product_brand=Sunshine Professional Peat Moss">Sunshine Professional Peat Moss</a>
<a class="side_nav" href="products_displayBrand.php?product_brand=Technigro Water Soluble Fertilizer">Technigro Water Soluble Fertilizer</a>
<a class="side_nav" href="products_displayBrand.php?product_brand=Strong-Lite">Strong-Lite</a>
<a class="side_nav" href="products_displayBrand.php?product_brand=Sunshine Bark-Based Mixes">Sunshine Bark-Based Mixes</a>
<a class="side_nav" href="products_packaging.php">Packaging Specifications</a>
<a class="side_nav" href="products_julian_mix.php">Julian Calendar</a>
</div>
<? echo "$columnSpacer"; ?>
</td>
<td class="body_main" width="100%" align="left" valign="top">
<? echo "<img src=\"images/layout/section_headers/$name.png\" alt=\"$title\" width=\"250\" height=\"41\" border=\"0\" />"; ?>
<p class="head"><? echo "$brand_name"; ?></p>
<p><? echo "$brand_description"; ?></p>
<div align="center"><? echo "<img src=\"images/products/$brand_image\" alt=\"$brand_name\" width=\"275\" height=\"226\" hspace=\"0\" vspace=\"10\" border=\"0\" />"; ?></div>
</td>
<td class="body_right" width="170" align="right" valign="top">
<img style="display: block;" src="images/photos/products_01.jpg" alt="Products" width="150" height="270" border="0" />
<? echo "$columnSpacer"; ?>
</td>
</tr>
</table>

<? echo "$incBodyEnd"; ?>

</div>
</body>
</html>


Help please.