Jump to content

PHP Navigation Bar and Product List Problems


timbo64

Recommended Posts

Hi PHP freaks,

 

i lately started to create a dynamic homepage. My Idea was to a Item List with the latest products and a dynamic navigation bar which reads out the Maincategories, subcategories and product names from an mysql database. So far so good. But the plan is also that if someone clicks on a product name in the navigation bar the user directly jumps to the product. Currently i have

 

The jumping process is working but here are the following errors:

 

1) If someone clicks on a product it always illustrates the product name and price and picture of product number 4 "Item 4", only the product details are correct. (e.g. Go to Main category 1 - subcategory 1 - item 1)

 

2) If i click on product number 2 "Item 2" the navigation bar stops to drop down and the list of the latest items is not displayed

 

I have no idea whats wrong here and i am lost. I need any help i can get, please. here is the website:

http://virbis-test.lima-city.de/index.php

 

this is the mysql database structure:

 

<html>

<table width="750" border="1">

  <tr>

    <td>produkt_id</td>

    <td>produkt_name</td>

    <td>hauptkategorie</td>

    <td>produkt_kategorie</td>

    <td>produkt_preis</td>

    <td>produkt_details</td>

    <td>date_added</td>

  </tr>

  <tr>

    <td>1</td>

    <td>Item 1</td>

    <td>Main categrory 1</td>

    <td>Subcategory 1</td>

    <td>4900</td>

    <td>Test test test</td>

    <td>2012-02-29</td>

  </tr>

  <tr>

    <td>3</td>

    <td>Item 3</td>

    <td>Main category 1</td>

    <td>Subcategory 3</td>

    <td>4500</td>

    <td>ewfgsfwfcdsvdfvfdvfdvdfvdddddddddddddddddddddd</td>

    <td>2012-03-01</td>

  </tr>

  <tr>

    <td>4</td>

    <td>Item 4</td>

    <td>Main category 3</td>

    <td>Subcategory 2</td>

    <td>4321</td>

    <td>ewffffffffffffffffffffffffffffffffffeeeeeeeee</td>

    <td>2012-03-02</td>

  </tr>

  <tr>

    <td>2</td>

    <td>Item 2</td>

    <td>Main category 2</td>

    <td>Subcategory 4</td>

    <td>32424</td>

    <td>Item 2 Item 2 Item 2 Item 2 Item 2</td>

    <td>2012-03-22</td>

  </tr>

</table>

</html>

 

i here is the code of the product page

 

<?php 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php 
// Check to see the URL variable is set and that it exists in the database
if (isset($_GET['produkt_id'])) {
// Connect to the MySQL database  
    include "verbindung_db.php"; 
$produkt_id = preg_replace('#[^0-9]#i', '', $_GET['produkt_id']); 
// Use this var to check to see if this ID exists, if yes then get the product 
// details, if no then exit this script and give message why
$sql = mysql_query("SELECT * FROM produkte WHERE produkt_id='$produkt_id' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
    if ($productCount > 0) {
	// get all the product details
	while($row = mysql_fetch_array($sql)){ 
		 $produkt_id = $row["produkt_id"];
		 $produkt_name = $row["produkt_name"];
		 $hauptkategorie = $row["hauptkategorie"];
		 $produkt_kategorie = $row["produkt_kategorie"];
		 $produkt_preis = $row["produkt_preis"];
		 $produkt_details = $row["produkt_details"];
         	 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
         }

} else {
	echo "That item does not exist.";
    exit();
}

} else {
echo "Data to render this page is missing.";
exit();
}
mysql_close();
?>
<?php 
// Run a select query to get my letest 6 items
// Connect to the MySQL database  
include "verbindung_db.php";

// Get latest products and products menu: begin
$Liste_Neu = "";
$sql = mysql_query("SELECT * FROM produkte ORDER BY date_added DESC");
$productCount = mysql_num_rows($sql); // count the output amount

$i = 0; // Neuste Gerate counter

$a_main_cat = array(); // main categories array

$a_subcat = array(); // subcategories array

$a_product = array(); // products array

if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
    
    if (!in_array($row['hauptkategorie'], $a_main_cat)) {
      $a_main_cat[] = $row['hauptkategorie'];
    }
    
    if (!isset($a_subcat[ $row['hauptkategorie'] ])) $a_subcat[ $row['hauptkategorie'] ] = array();
    
    if (!in_array($row['produkt_kategorie'], $a_subcat[ $row['hauptkategorie'] ])) {
      $a_subcat[ $row['hauptkategorie'] ][] = $row['produkt_kategorie'];
    }
    
    $a_product[ $row['hauptkategorie'] ][ $row['produkt_kategorie'] ][ $row["produkt_id"] ] = $row["produkt_name"];

    if ($i<5) {
      $produkt_id = $row["produkt_id"];
      $produkt_name = $row["produkt_name"];
      $produkt_preis = $row["produkt_preis"];
      $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
      $Liste_Neu .= '<table width="100%" cellspacing="0" cellpadding="6">
      <tr>
        <td width="17%" valign="left"><a href="produkte.php?produkt_id=' . $produkt_id . '"><img style="border:#666 1px solid;" src="produkt_bilder/' . $produkt_id . '.jpg" alt="' . $produkt_name . '" width="77" height="102" border="1" /></a></td>
        <td width="83%" valign="left">' . $produkt_name . '<br />
          ' . $produkt_preis . ' Euro<br />
          <a href="produkt.php?produkt_id=' . $produkt_id . '">Produkt Details</a></td>
      </tr>
      </table>';
    }
    $i++;
  }
} else {
$Liste_Neu = "Kein Produkt im Store";
}

sort($a_main_cat);
reset($a_main_cat);
foreach ($a_main_cat AS $v) {
  sort($a_subcat[$v]);
  reset($a_subcat[$v]);
  foreach ($a_subcat[$v] AS $v2) {
    asort($a_product[ $v ][ $v2 ]);
    reset($a_product[ $v ][ $v2 ]);
  }
}
// Get latest products and products menu: end

mysql_close();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<head profile="http://gmpg.org/xfn/11">

<title><?php echo $produkt_name; ?></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />

<link rel="stylesheet" href="styles/layout.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="ddsmoothmenu.css" />
<link rel="stylesheet" type="text/css" href="ddsmoothmenu-v.css" />

<script type="text/javascript" src="scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="scripts/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="scripts/jquery.hoverIntent.js"></script>
<script type="text/javascript" src="scripts/jquery.hslides.1.0.js"></script>
<script type="text/javascript" src="scripts/jquery.hslides.setup.js"></script>
<script type="text/javascript" src="ddsmoothmenu.js"></script>

<script type="text/javascript">

ddsmoothmenu.init({
mainmenuid: "smoothmenu1", //menu DIV id
orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu', //class added to menu's outer DIV
//customtheme: ["#1c5a80", "#18374a"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

</script>
</head>
<body id="top">
<!----------------------------------------------- Header ----------------------------------------------->
<div id="header">
  <div class="wrapper">
    <div class="logo">

      <table width="920px">
  <tr>
    <td><center><h1><a href="#"><img src="http://www10.pic-upload.de/thumb/01.02.12/gvu9ae66m53g.jpg" alt="" /></a></h1></center></td>
    <td><center><h1><a href=""><img src="http://www10.pic-upload.de/03.02.12/tjsla3rvmeaj.jpg" alt="" width="85%" height="85%" /></a></h1></center></td>
  </tr>
</table>
    </div>
    

    <br class="clear" />
  </div>
</div>

<!-- ##################################################### Navigation ##################################################### -->

<div id="topbar">
  <div class="wrapper">
  <div id="smoothmenu1" class="ddsmoothmenu">
<ul>
<li><a href="http://virbis-test.lima-city.de/index.php">Home</a></li>
<li><a href="#">Produkte</a>
  <ul>
  <?php
    // Generate products submenu: begin
    foreach ($a_main_cat AS $k) {
      echo '<li><a href="#">'.$k.'</a>';
      if (isset($a_subcat[$k]) && $a_subcat[$k]) {
        echo '<ul>';
        foreach ($a_subcat[$k] AS $v) {
          echo '<li><a href="#">'.$v.'</a>';
          if (isset($a_product[ $k ][ $v ]) && $a_product[ $k ][ $v ]) {
            echo '<ul>';
            foreach ( $a_product[ $k ][ $v ] AS $k2 => $v2 ) {
              echo '<li><a href="produkte.php?produkt_id='.$k2.'">'.$v2.'</a></li>';
            }
            echo '</ul>';
          }
          echo '</li>';
        }
        echo '</ul>';
      }
      echo '</li>';
    }
    // Generate products submenu: end
  ?>
  </ul>
</li>

<li><a href="#">Service</a>
  <ul>
  <li><a href="http://virbis-test.lima-city.de/geraetesuche.php">Gerätesuche</a></li>
  <li><a href="#">Kommissionsverkauf</a></li>
  </ul>
</li>

<li><a href="http://virbis-test.lima-city.de/kontakt.php">Kontakt</a></li>

<li><a href="http://virbis-test.lima-city.de/impressum.php">Impressum</a></li>
</ul>


<!-- ##################################################### Ende Navigation ##################################################### -->


<div id="search">

    <center>facebook_img</center>
    </div>
    <br class="clear" />
</div>  
</div>  
</div>



<div id="container">
  <div class="wrapper">
    <div id="content">

<table width="100%" border="0" cellspacing="0" cellpadding="15">
  <tr>
    <td width="19%" valign="top"><img src="produkt_bilder/<?php echo $produkt_id; ?>.jpg" width="142" height="188" /><br />
      <a href="produkt_bilder/<?php echo $produkt_id; ?>.jpg">View Full Size Image</a></td>
    <td width="81%" valign="top"><h3><?php echo $produkt_name; ?></h3>
      <p><?php echo .$produkt_preis ; ?>Euro</p><br />
        <br />
<br />
       <p> <?php echo $produkt_details; ?>
<br />
        </p>
      <form id="form1" name="form1" method="post" action="cart.php">
        <input type="hidden" name="pid" id="pid" value="<?php echo $produkt_id; ?>" />
        <input type="submit" name="button" id="button" value="Add to Shopping Cart" />
      </form>
      </td>
    </tr>
</table>
</div>

<div id="column">
      <div class="holder">
  
  <h2>Neuste Geräte</h2>
  
  <p><?php echo $Liste_Neu ?></p>
  
  </div>
</div>



    <br class="clear" />
  </div>
</div>


<div id="footer">
  <div class="wrapper">
    <div id="newsletter">
      <h2>Kostenloser Newsletter</h2>
  <p>Infos über neuste Geräte und Services</p>
<!-- Begin Signup Form -->
<link href="http://cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">
<style type="text/css">
#mc_embed_signup{background:#B2B2B2; clear:left; font:14px Helvetica,Arial,sans-serif; }
</style>
<div id="mc_embed_signup">
<form action="http://laborgeraete-muenchen.us2.list-manage.com/subscribe/post?u=89ec80c53c5524c1af0336097&id=a846bbc9b0" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank">

<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email addresse" required>
<div class="clear"><input type="" value="einloggen" name="einloggen" id="mc-embedded-subscribe" class="button"></div>
</form>
</div>

<!--End mc_embed_signup-->
    </div>
    <div class="footbox">
      <h2>Unternehmen</h2>
      <ul>
        <li><a href="#">Kontakt</a></li>
	<li><a href="#">AGB</a></li>
        <li class="last"><a href="#">Impressum</a></li>
      </ul>
    </div>
    <div class="footbox">
      <h2>Presse und Partner</h2>
      <ul>
        <li><a href="#"></a></li>
        <li><a href="#"></a></li>
        <li><a href="#"></a></li>
        <li><a href="#"></a></li>
        <li class="last"><a href="#"></a></li>
      </ul>
    </div>
    <div class="footbox">
      <h2>Service</h2>
      <ul>
        <li><a href="#">Laborgeräte suchen</a></li>
        <li class="last"><a href="#">Kommissionsverkauf</a></li>
      </ul>
    </div>
    <br class="clear" />
  </div>
</div>

<!-- ################################################## Copyright ##################################################### -->

<div id="copyright">
  <div class="wrapper">
    <p class="fl_left">Copyright © 2012 - All Rights Reserved - <a href="#">Laborgeräte München</a></p>
    <p class="fl_right">Template von <a href="http://www.virbis.de/" >Virbis</a></p>
    <br class="clear" />
  </div>
</div>
</body>
</html>

 

help is appreciated it very much

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.