php - Selecting row from array using session functions -



php - Selecting row from array using session functions -

i'm trying create store page stuck @ adding product cart. through sessions using array. right function add together 1 of each row, while want add together 1 row button in. below code.

<?php //initialization session_start(); include ("store_functions.php"); //variables $var = ""; if (isset($_get['sort'])) { $var = "?sort=".$_get['sort']; } //table info $products = array(); $products[] = array("product" => "payday2", "system" => "pc", "price" => 29.99); $products[] = array("product" => "metal gear solid 5", "system" => "ps4", "price" => 49.99); $products[] = array("product" => "the lastly of us", "system" => "ps3", "price" => 34.99); $products[] = array("product" => "forza 5", "system" => "xbox one", "price" => 59.99); $products[] = array("product" => "gran turismo 6", "system" => "ps3", "price" => 59.99); //sorting table function if (isset($_get['sort'])) { switch ($_get['sort']) { case "prod": $func = "sort_product"; break; case "sys": $func = "sort_system"; break; case "prc": $func = "sort_price"; break; default: $func = "sort_product"; break; } usort ($products, $func); } ?>

<!doctype html> <html> <head> <title> gamestore 0 </title> </head> <body> <table border='1'> <th> <a href='?sort=prod'>product</a> </th> <th> <a href='?sort=sys'>compatibility</a> </th> <th> <a href='?sort=prc'>price</a> </th> <th> add together cart </th> <tbody> <?php echo listing_array($products, $var);?> </tbody> </table> <div> <p> shopping cart </p> <p> <?php $func = add_product(); var_dump($func);?> </p> <p> grand total: $ </p> </div> </body> </html> <?php //array listing (function) function listing_array ($products, $var){ $html = ""; foreach ($products $key => $value) { $html.= "<tr><td>".$value["product"]."</td><td>".$value["system"]." </td><td>".$value["price"]."</td><td><form action='store_session.php".$var."' method='post'> <input type='submit' name='atc' value='add'/><iput type='hidden' name='session_var' value='1'/></form></td></tr>"; } homecoming $html; } //sorting functionality (per array $product) function sort_product ($a, $b) { if ($a["product"]==$b["product"]) { homecoming 0; } if ($a["product"]<$b["product"]) { homecoming -1; } homecoming 1; } //sorting functionality (per array $system) function sort_system ($a, $b) { if ($a["system"]==$b["system"]) { homecoming 0; } if ($a["system"]<$b["system"]) { homecoming -1; } homecoming 1; } //sort functionality (per array $price) function sort_price ($a, $b) { if ($a["price"]==$b["price"]) { homecoming 0; } if ($a["price"]<$b["price"]) { homecoming -1; } homecoming 1; } //add new item cart(function) function add_product () { if (isset($_session['session_var'])) { $_session['session_var']++; } else { $_session['session_var'] = "0"; } homecoming $_session['session_var']; } ?>

php arrays function session counter

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -