I have to display a ordered associative array that contains some products and their quantity in three years. When I click radio buttons and it doesnt work with build-in functions such as asort or arsort. I have created two radio buttons where I can choose if I want my array to be in ASC or DESC, but when i clicked in one of it nothing happens in my tables. What can I do?
<form action="#" method="post">
<p style="color:red;">Afishoni te dhenat per pajisjet elektronike duke perzgjedhur si me poshte:</p>
<input type="checkbox" name="viti1" value="Viti i pare"/>Viti i pare
<input type="checkbox" name="viti2" value="Viti i dyte"/>Viti i dyte
<input type="checkbox" name="viti3" value="Viti i trete"/>Viti i trete<br>
*Zgjidh nje ose me shume vite per te afishuar te dhenat<br><br>
Rendit te dhenat e pajisjeve ne baze te volumit te shitjeve ne rendin:<br>
<input type="radio" name="renditja" <?php if(isset($renditja) && $renditja=="rrites") {asort($pajisjet_viti1);} ?>
value="rrites"/>Rrites
<input type="radio" name="renditja" <?php if(isset($renditja) && $renditja=="zbrites") {array_multisort($pajisjet_viti1,SORT_DESC,$pajisjet_viti2,SORT_DESC,$pajisjet_viti3,SORT_DESC);} ?>
value="zbrites"/>Zbrites<br><br>
<input type="submit" name="submit" value="Kerko"/>
</form>
<?php
//krijimi i vektoreve te asociuar dy dimensionale per 3 vitet
$pajisjet_viti1 = array
(
array("Televizor"=>2200,"IPhone"=>1500,"Laptop"=>5000,"Kamera"=>1700, "Nintendo Wii"=>2000,"Kindle Fire"=>1500,"PSP"=>1500,"IPad"=>1700, "Mikrovale"=>3300,"Printer"=>2250,"XBox 360"=>1000,"UPS"=>300)
);
$pajisjet_viti2 = array
(
array("Televizor"=>3200,"IPhone"=>1000,"Laptop"=>5500,"Kamera"=>1100,"Nintendo Wii"=>1000,"Kindle Fire"=>1400,"PSP"=>1000,"IPad"=>1650,"Mikrovale"=>3255,"Printer"=>2257,"XBox 360"=>1122,"UPS"=>700)
);
$pajisjet_viti3 = array
(
array("Televizor"=>4210,"IPhone"=>1560,"Laptop"=>5780,"Kamera"=>1962, "Nintendo Wii"=>299,"Kindle Fire"=>500,"PSP"=>1690,"IPad"=>3880, "Mikrovale"=>3320,"Printer"=>2250,"XBox 890"=>1000,"UPS"=>1000)
);
//per te kontrolluar nese eshte shtypur butoni kerko dhe nese eshte zgjedhur te pakten nje nga vitet
if(isset($_POST['submit'])){
if(!isset($_POST['viti1']) && !isset($_POST['viti2']) && !isset($_POST['viti3'])){
echo "<br><br>Zgjidh nje ose me shume vite per te afishuar te dhenat";
}
//per te kontrolluar nese eshte shtypur viti1 dhe per te shfaqur tabelen ne rast se ai eshte klikuar
if(isset($_POST['viti1'])){
asort($pajisjet_viti1);
echo "<table border='1' cellspacing=0 cellpadding=0>
<caption>Viti i pare</caption>
<tr>
<th>Produkti </th>
<th>Sasia</th>
</tr>";
for($r=0;$r<count($pajisjet_viti1);$r++)
{ echo "<tr>";
foreach($pajisjet_viti1[$r] as $key=>$value)
{
echo "<td>".$key."</td><td>".$value."</td></tr> ";
}
}
}
//per te kontrolluar nese eshte shtypur viti2 dhe per te shfaqur tabelen ne rast se ai eshte klikuar
if(isset($_POST['viti2'])){
//arsort($pajisjet_viti2);
echo "<table border='1' cellspacing=0 cellpadding=0>
<caption>Viti i dyte</caption>
<tr>
<th>Produkti </th>
<th>Sasia</th>
</tr>";
for($r=0;$r<count($pajisjet_viti2);$r++)
{ echo "<tr>";
foreach($pajisjet_viti2[$r] as $key=>$value)
{
echo "<td>".$key."</td><td>".$value."</td></tr> ";
}
}
}
//per te kontrolluar nese eshte shtypur viti3 dhe per te shfaqur tabelen ne rast se ai eshte klikuar
if(isset($_POST['viti3'])){
echo "<table border='1' cellspacing=0 cellpadding=0>
<caption>Viti i trete</caption>
<tr>
<th>Produkti </th>
<th>Sasia</th>
</tr>";
for($r=0;$r<count($pajisjet_viti3);$r++)
{ echo "<tr>";
foreach($pajisjet_viti3[$r] as $key=>$value)
{
echo "<td>".$key."</td><td>".$value."</td></tr> ";
}
}
}
}
?>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire