Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [jQuery]Update Koszyka
pa-jong
post
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 1
Dołączył: 21.02.2008
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Witam,

Od dłuższego czasu próbuje przerobić poniższy skrypt tak aby działał bez przeładowania strony..
do tej pory udało mi się zrobić dodawanie oraz usuwanie poległem niestety przy update..

czy znajdzie się ktoś kto pomoże mi rozwiązać tą kwestię ?




Formularz.
  1. <form action="admin.php?tab=koszyk&action=update" method="post" id="cart" >
  2.  
  3. (...)
  4.  
  5. <input name="qty'.$id.'" title="Enter = zapisz" class="editores" style="width:20px;" type="text" value="'.$qty.'" onkeypress="handleKeyPress(event,this.form)">



Skrypt odpowiedzialny za update..
  1. (...)
  2.  
  3. case 'update':
  4. if ($cart) {
  5. $newcart = '';
  6. foreach ($_POST as $key=>$value) {
  7. if (stristr($key,'qty')) {
  8. $id = str_replace('qty','',$key);
  9. $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
  10. $newcart = '';
  11. foreach ($items as $item) {
  12. if ($id != $item) {
  13. if ($newcart != '') {
  14. $newcart .= ','.$item;
  15. } else {
  16. $newcart = $item;
  17. }
  18. }
  19. }
  20. for ($i=1;$i<=$value;$i++) {
  21. if ($newcart != '') {
  22. $newcart .= ','.$id;
  23. } else {
  24. $newcart = $id;
  25. }
  26. }
  27. }
  28. }
  29. }
  30. $cart = $newcart;
  31. break;
  32. }
  33.  
  34.  
  35. //// zdublowany update z $_GET używany obecnie..
  36. if ($_GET['action'] == 'update') {
  37. if ($cart) {
  38. $newcart = '';
  39. foreach ($_POST as $key=>$value) {
  40. if (stristr($key,'qty')) {
  41. $id = str_replace('qty','',$key);
  42. $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
  43. $newcart = '';
  44. foreach ($items as $item) {
  45. if ($id != $item) {
  46. if ($newcart != '') {
  47. $newcart .= ','.$item;
  48. } else {
  49. $newcart = $item;
  50. }
  51. }
  52. }
  53. for ($i=1;$i<=$value;$i++) {
  54. if ($newcart != '') {
  55. $newcart .= ','.$id;
  56. } else {
  57. $newcart = $id;
  58. }
  59. }
  60. }
  61. }
  62. }
  63. $cart = $newcart;
  64. }
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
pa-jong
post
Post #2





Grupa: Zarejestrowani
Postów: 64
Pomógł: 1
Dołączył: 21.02.2008
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


HTML wygląda mniej więcej tak..
  1. function showCart() {
  2. global $db;
  3. $cart = $_SESSION['cart'];
  4. if ($cart) {
  5. $items = explode(',',$cart);
  6. $contents = array();
  7. foreach ($items as $item) {
  8. $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
  9. }
  10.  
  11.  
  12. $output[] = '<div style="width: auto; height: auto; position: relative; " class="ui-dialog ui-widget ui-widget-content ui-corner-all" >';
  13. $output[] = ' <div id="dialog" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 118px; height: auto; display: block; ">';
  14. $output[] = ' <fieldset>';
  15. $output[] = ' <legend>Twoje zamówienie</legend>';
  16.  
  17. $output[] = ' <form method="post" id="cart">';
  18. $output[] = ' <table class="content-item" border="0" cellspacing="0" cellpadding="2">';
  19. $output[] = ' <thead>';
  20. $output[] = ' <tr class="ui-widget-header">';
  21. $output[] = ' <td style="width:20px;">lp.</td>';
  22. $output[] = ' <td style="width: 80px;">Symbol</td>';
  23. $output[] = ' <td>Nazwa</td>';
  24. $output[] = ' <td style="width:40px;">Ilość<br>Mag.</td>';
  25. $output[] = ' <td style="width:40px;">Ilosć<br>sklep</td>';
  26. $output[] = ' <td style="width:55px;">Ilość</td>';
  27. $output[] = ' <td style="width:40px;">Jedn.</td>';
  28. $output[] = ' <td style="width:30px;">Vat</td>';
  29. $output[] = ' <td style="width:80px;">Cena Netto</td>';
  30. $output[] = ' <td style="width:80px;">Cena Brutto</td>';
  31. $output[] = ' <td style="width:80px;">Brutto Razem</td>';
  32. $output[] = ' <td style="width:15px;"></td>';
  33. $output[] = ' </tr>';
  34. $output[] = ' </thead>';
  35. $output[] = ' <tbody>';
  36.  
  37.  
  38. $i = 0;
  39. foreach ($contents as $id=>$qty) {
  40. $i++;
  41.  
  42. $sql = "SELECT * FROM stany WHERE Symbol = '".$id."'";
  43. $result = $db->query($sql);
  44. $row = $result->fetch();
  45. extract($row);
  46.  
  47.  
  48.  
  49. $output[] = ' <tr id="item'.$id.'"class="ui-state-default">';
  50. $output[] = ' <td valign="top"> '.$i.'. </td>';
  51. $output[] = ' <td valign="top" style="color: #4d8214; class="username-coloured"> '.$id.' </td>';
  52. $output[] = ' <td style="width:300px; '.$col.'" valign="top">';
  53. $output[] = ' '.$Nazwa.'</td>';
  54. $output[] = ' <td valign="top">'.$skl1.'</td>';
  55. $output[] = ' <td valign="top">'.$skl11.'</td>';
  56. $output[] = ' <td valign="top">';
  57. $output[] = ' <div style="display:inline;" id="count'.$id.'">';
  58. $output[] = ' <a href="java script:void(0)" class="ui-icon ui-icon-pencil" style="float: left; cursor: auto; " title="Zmień ilość produktów" onclick="$("#count'.$id.'").attr("style","display:none");$("#countUpdate'.$id.'").attr("style","display:inline");">';
  59. $output[] = ' </a>'.$qty.'';
  60. $output[] = ' </div>';
  61. $output[] = ' <div style="display:none;" id="countUpdate'.$id.'">';
  62. $output[] = ' <a href="java script:void(0)" class="ui-icon ui-icon-close" style="float: left; cursor: auto; " onclick="$("#countUpdate'.$id.'").attr("style","display:none");$("#count'.$id.'").attr("style","display:inline");">';
  63. $output[] = ' </a>';
  64. $output[] = ' <input name="action" value="update" type="hidden">';
  65. $output[] = ' <input name="qty'.$id.'" id="qty'.$id.'" title="Enter = zapisz" class="editores" style="width:20px;" type="text" value="'.$qty.'" onkeypress="handleKeyPress(event,this.form)">';
  66. $output[] = ' </div></td>';
  67. $output[] = ' <td valign="top">egz.</td>';
  68. $output[] = ' <td valign="top">5%</td>';
  69. $output[] = ' <td valign="top"> 397.78 PLN</td>';
  70. $output[] = ' <td valign="top">'.$skl1Cena.' PLN</td>';
  71. $output[] = ' <td style="width:60px;" valign="top">'.($skl1Cena * $qty).' PLN</td>';
  72. $output[] = ' <td valign="top">';
  73. $output[] = " <a href='java script:uzk(\"".$id."\",\"delete\")' onClick='$(\"#item".$id."\").fadeOut(\"slow\")' class='ui-icon ui-icon-trash' style='float: left; cursor: auto; ' title='usuń z zamówienia'>";
  74. $output[] = ' </a></td>';
  75. $output[] = ' </tr>';
  76.  
  77.  
  78. }


Ten post edytował pa-jong 11.05.2012, 20:46:22
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 15:15