0

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

http://alisgfx.com/lomo/

轮播中的项目是从带有 phpforeach 的数组中加载的。我想要做的是当您单击一个项目时,您将转到名为 index.php?product=productname 的下一页

我认为获取变量是一种选择,但我不知道如何将它与我的数组结合起来。我怎样才能简单地实现这一目标?

索引.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';

 ?>

函数.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.')
);

?>
4

2 回答 2

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”);像上面这样的东西可以工作。

于 2012-12-28T17:38:46.270 回答
0

在您的元素周围添加一个<a href>链接-<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>
    ';
}

编辑

您想检查是否选择了产品并显示信息,如果没有,则显示您的产品列表。我注意到$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';
?>
于 2012-12-28T17:41:11.570 回答