2012-12-28 86 views
0

我需要一些帮助以下网站/网上商店。

http://alisgfx.com/lomo/

在转盘中的项目从与phpforeach阵列加载。我想要做的是当你点击一个项目,你会去到一个名为index.php的下一个页面?product = productname

我认为变量是一个选项,但我不知道如何将它与我的数组。 我该如何简单地实现这一目标?

的index.php

<?php 
# include de benodigde bestanden (require geeft een fatale fout als het niet lukt) 
require('inc/config.inc.php'); 
require('inc/functions.inc.php'); 
require('inc/template.inc.php'); 

# geef de HTML code voor het openen van de pagina weer 
htmlOpenen('Introtekst'); 

toonHeader(); 

include 'menu.php'; 

?> 

<!-- producten carousel --> 
<section class="carousel"> 
    <div class="banner"><img src="img/nieuw.jpg"></div> 
    <div id="slider1"> 
     <a class="buttons prev" href="#">left</a> 
     <div class="viewport"> 
      <ul class="overview"> 
       <?php 
       foreach($nieuwBinnen as $new) { 
        echo ' 
         <li> 
          <h2>'.$new['naam'].'</h2> 
          <p>'.$new['product'].'</p> 
         </li> 
        '; 
       } 
       ?> 
      </ul> 
     </div> 
     <a class="buttons next" href="#">right</a> 
    </div> 
</section> 

<section class="carousel"> 
    <div class="banner"><img src="img/best.jpg"></div> 
    <div id="slider2"> 
     <a class="buttons prev" href="#">left</a> 
     <div class="viewport"> 
      <ul class="overview"> 
       <?php 
       foreach($bestSellers as $bestseller) { 
        echo ' 
         <li> 
          <h2>'.$bestseller['naam'].'</h2> 
          <p>'.$bestseller['product'].'</p> 
         </li> 
        '; 
       } 
       ?> 
      </ul> 
     </div> 
     <a class="buttons next" href="#">right</a> 
    </div> 
</section> 


<?php 

include 'footer.php'; 

?> 

的functions.php

<?php 
#functies 


$nieuwBinnen = array(

    array('naam' => 'Product 1', 
      'product' => 'img', 
      'info' => 'Everybody loves microcontrollers, including the Arduino, allowing you to create whatever you imagine. That is unless you want to hack together something wireless. Originally you had to rely on the expensive XBee protocol or other wireless options, but no longer. Hobby Robotics found an extremely cheap transmitter and receiver and wrote a quick guide for wiring them up to an Arduino. Now your wireless projects can come to life, as long as you are within 500 feet and don’t mind 2400bps; minor trade offs compared to the gains of wireless freedom. Final note: You aren’t limited to Arduino, we would love to see someone modify this to work with a PIC or other microcontroller.', 
      'prijs' => 'img', 
      'beschik' => 'op voorraad', 
      'fotos' => 'imgs', 
      'upload' => 'imgs'), 

    array('naam' => 'Product 2', 
      'product' => 'img', 
      'info' => '[Joey] sent us a link to his Gameboy foot controller. In the video above, you can see him using it to control the loops in the background while he plays his guitar through an 8-bit filter. He tells us that several gameboys were used in the construction. At one point, he had to replace the guts because the music was so loud it knocked his equipment over and destroyed it. We can’t help but feel just a tiny bit of excitement as memories of renting a NES cartridge for the weekend fill our heads when we hear these riffs. His music isn’t too bad either. There is a growing crowd of people that support “chip music”. You can see what looks like a decent sized gathering enjoying a show with a little bit of a history lesson after the break.'), 

    array('naam' => 'Product 3', 
      'product' => 'img', 
      'info' => 'The Linux4nano project has been working to port the Linux kernel onto the iPod Nano along with other iPods in general. Although the iPodLinux project has had luck with some older iPods, newer models protect firmware updates with encryption. One of the ways they plan on running code on the device is through a vulnerability in the notes program; it causes the processor to jump to a specific instruction and execute arbitrary code. To take advantage of this, they first need to figure out where their injected code ends up in the memory. Currently, they are testing every memory location by painstakingly loading in a bogus note and recording its effect. Each note takes about a minute to test and they have tens of thousands of addresses to check over several devices.'), 

    array('naam' => 'Product 4', 
      'product' => 'img', 
      'info' => 'The MIT Camera Culture Group utilized Bokeh, an effect where the lens is purposely placed out of focus, in order to vastly improve current 2D barcode technology. Dubbed Bokode, the team claims that an off the shelf camera can read data 2.5 microns from a distance of over 4 meters, compared to today’s average barcode reader’s maximum distance of only a foot or so. What looks most interesting is the ability to produce a smoother and more accurate distance and angle calculations (relative to the camera): allowing for a better augmented reality. It also seems to be more secure than traditional 2D barcodes, that is of course until the hacker community gets a hold of it.'), 

    array('naam' => 'Product 5', 
      'product' => 'img', 
      'info' => '[Peter Kirn] over at Create Digital Music takes an in depth look at the process of adding your own music to Rock Band 2. This involves using REAPER audio production software, uploading your work via the XNA Creators’ Club, and then playing the fresh track on an Xbox 360. Both REAPER and the XNA Club cost money, and the total price comes out somewhere between $100-$160. The process is now in closed beta but a wider beta is expected in September followed by a full release in October.') 
); 


$bestSellers = array(

    array('naam' => 'Product 1', 
      'product' => 'img', 
      'info' => 'Everybody loves microcontrollers, including the Arduino, allowing you to create whatever you imagine. That is unless you want to hack together something wireless. Originally you had to rely on the expensive XBee protocol or other wireless options, but no longer. Hobby Robotics found an extremely cheap transmitter and receiver and wrote a quick guide for wiring them up to an Arduino. Now your wireless projects can come to life, as long as you are within 500 feet and don’t mind 2400bps; minor trade offs compared to the gains of wireless freedom. Final note: You aren’t limited to Arduino, we would love to see someone modify this to work with a PIC or other microcontroller.'), 

    array('naam' => 'Product 2', 
      'product' => 'img', 
      'info' => '[Joey] sent us a link to his Gameboy foot controller. In the video above, you can see him using it to control the loops in the background while he plays his guitar through an 8-bit filter. He tells us that several gameboys were used in the construction. At one point, he had to replace the guts because the music was so loud it knocked his equipment over and destroyed it. We can’t help but feel just a tiny bit of excitement as memories of renting a NES cartridge for the weekend fill our heads when we hear these riffs. His music isn’t too bad either. There is a growing crowd of people that support “chip music”. You can see what looks like a decent sized gathering enjoying a show with a little bit of a history lesson after the break.'), 

    array('naam' => 'Product 3', 
      'product' => 'img', 
      'info' => 'The Linux4nano project has been working to port the Linux kernel onto the iPod Nano along with other iPods in general. Although the iPodLinux project has had luck with some older iPods, newer models protect firmware updates with encryption. One of the ways they plan on running code on the device is through a vulnerability in the notes program; it causes the processor to jump to a specific instruction and execute arbitrary code. To take advantage of this, they first need to figure out where their injected code ends up in the memory. Currently, they are testing every memory location by painstakingly loading in a bogus note and recording its effect. Each note takes about a minute to test and they have tens of thousands of addresses to check over several devices.'), 

    array('naam' => 'Product 4', 
      'product' => 'img', 
      'info' => 'The MIT Camera Culture Group utilized Bokeh, an effect where the lens is purposely placed out of focus, in order to vastly improve current 2D barcode technology. Dubbed Bokode, the team claims that an off the shelf camera can read data 2.5 microns from a distance of over 4 meters, compared to today’s average barcode reader’s maximum distance of only a foot or so. What looks most interesting is the ability to produce a smoother and more accurate distance and angle calculations (relative to the camera): allowing for a better augmented reality. It also seems to be more secure than traditional 2D barcodes, that is of course until the hacker community gets a hold of it.'), 

    array('naam' => 'Product 5', 
      'product' => 'img', 
      'info' => '[Peter Kirn] over at Create Digital Music takes an in depth look at the process of adding your own music to Rock Band 2. This involves using REAPER audio production software, uploading your work via the XNA Creators’ Club, and then playing the fresh track on an Xbox 360. Both REAPER and the XNA Club cost money, and the total price comes out somewhere between $100-$160. The process is now in closed beta but a wider beta is expected in September followed by a full release in October.') 
); 

?> 
+0

在PHP中,变量名称区分大小写。 $ _get!= $ _GET。后者是正确的。 –

回答

0

添加在你<li>元素 -

foreach($nieuwBinnen as $new) { 
    echo ' 
     <li> 
      <a href="index.php?category=new&product='.urlencode($new['naam']).'"> 
      <h2>'.$new['naam'].'</h2> 
      <p>'.$new['product'].'</p> 
      </a> 
     </li> 
    '; 
} 

foreach($bestSellers as $bestseller) { 
    echo ' 
     <li> 
      <a href="index.php?category=bestseller&product='.urlencode($bestseller['naam']).'"> 
      <h2>'.$bestseller['naam'].'</h2> 
      <p>'.$bestseller['product'].'</p> 
      </a> 
     </li> 
    '; 
} 

编辑<a href>链接

你想如果选择的产品检查并显示信息,如果是这样,如果没有显示你的产品列表。我注意到$nieuwBinnen & $bestSellers有同样的产品。我认为这并非总是如此,因此您需要将category=添加到您的链接中,以选择从(index.php?category=#&product=#)中选择产品的阵列。下面没有测试,但应该把你放在正确的方向。

if (isset($_GET['category']) && isset($_GET['product']) && isset($$_GET['category'])){ //display product if provided 
    $category = $$_GET['category']; 
    $product = $_GET['product']; 
    $error_msg = 1; //sets a basic error catcher in case product does not exist 
    foreach ($category as $item) { 
     if ($item['naam'] == $product) { 
     echo $item['naam']."<br/>"; 
     echo $item['product']."<br/>"; 
     echo $item['info']."<br/>"; 
     $error = 0; 
     }  
    } 
if ($error_msg){ //basic error message in case product does not exist 
    echo 'The selected product no longer exists'; 
} 
}   
else{ //displays all product if specific product not given 
?> 
<!-- producten carousel --> 
<section class="carousel"> 
    <div class="banner"><img src="img/nieuw.jpg"></div> 
    <div id="slider1"> 
     <a class="buttons prev" href="#">left</a> 
     <div class="viewport"> 
      <ul class="overview"> 
       <?php 
       foreach($nieuwBinnen as $new) { 
        echo ' 
         <li> 
          <a href="index.php?category=nieuwBinnen&product='.urlencode($new['naam']).'"> 
          <h2>'.$new['naam'].'</h2> 
          <p>'.$new['product'].'</p> 
          </a> 
         </li> 
        '; 
       } 
       ?> 
      </ul> 
     </div> 
     <a class="buttons next" href="#">right</a> 
    </div> 
</section> 

<section class="carousel"> 
    <div class="banner"><img src="img/best.jpg"></div> 
    <div id="slider2"> 
     <a class="buttons prev" href="#">left</a> 
     <div class="viewport"> 
      <ul class="overview"> 
       <?php 
       foreach($bestSellers as $bestseller) { 
        echo ' 
         <li> 
          <a href="index.php?category=bestSellers&product='.urlencode($new['naam']).'"> 
          <h2>'.$bestseller['naam'].'</h2> 
          <p>'.$bestseller['product'].'</p> 
          </a> 
         </li> 
        '; 
       } 
       ?> 
      </ul> 
     </div> 
     <a class="buttons next" href="#">right</a> 
    </div> 
</section> 
<?php 
} 

include 'footer.php'; 
?> 
+0

谢谢。我做了这个,现在url更改为index.php?product = product1 但它没有显示产品及其值。接下来我应该做什么? –

+0

我已经添加了一些示例代码,说明如何选择是否显示产品详细信息或产品列表,如果设置了'?product = product1',则基于off。请注意,我在该链接中添加了“category = category”,因为您的产品可能不会始终位于两个阵列中。代码未经测试,但应指向正确的方向。 – Sean

+0

谢谢一堆,它的作品! –

0
  foreach($bestSellers as $bestseller) { 
       echo ' 
        <li> 
         <a href="index.php?product='.$bestseller['naam'].'"> 
          <h2>'.$bestseller['naam'].'</h2> 
          <p>'.$bestseller['product'].'</p> 
         </a> 
        </li> 
       '; 
      } 

除了这个问题对于你在你的产品的名称空间(你应该用解决一个对URL友好的标识符,例如“Product-1”);像上面的东西可以工作。

+1

可能会想要在URL中使用urlencode($ bestseller ['naam'])。 –

相关问题