我需要以下网站/网上商店的帮助。
轮播中的项目是使用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 :(得分: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 :(得分: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
&amp; $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';
?>