2012-12-28 25 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'])。 –

相關問題