I create an array from here. This is my Ajah or jQuery basket. Even he got confused.

Arrays.push(thisID); var t = $('.cart-total span').html(); t = Number(t) + Number(qiymet) $('.cart-total span').html(t.toFixed(2)); $('#total-hidden-charges').val(t.toFixed(2)); $('#left_bar .cart-info').append('<div class="shopp" id="each-' + thisID + '"><span class="label">' + mal_name + '</span><span style="float:left;width:102px;border-right-width: 2px;border-right-style: solid;border-right-color: #ccc;"><span class="az"></span><span class="mal_say">1</span>&nbsp;' + eded + '<span class="cox"></span></span><span class="price"><em>' + qiymet + '</em> man.</span><span class="endir"><input type="text" id="end" size="3" style="height:8px; font-size:11px; margin-top:-6px;"/> man.</span><span class="hesab" id="hesab"><em>' + qiymet + '</em> man.</span><img src="img/remove.png" class="remove" /><br class="all" /></div>'); 

and in the array just as .label is being pushed, this is the type of product name, the guys in my array are not the correct mine.

 $('#save').livequery('click', function () { var newarr = new Array(); arr = $('.label'); for (i = 0; i < arr.length; i++) newarr.push($(arr[i]).html()); alert(newarr); $.post('save.php', { arr: newarr }, function (data) { $('#result').html(data); }); }); 

Help me please.

Here is my pkhp, which takes an array.

 <? if (isset($_POST['arr'])) { echo '<div id="iframe"> <div class="shopp"> <span class="label">'.$_POST['arr'].'</span> <span class="mal_sayi">5 kletka</span> <span class="mal_umum_qiymet">цена</span> <span class="endir">скидка</span> <span class="hesab">сумма</span> <br class="all" /> </div><br> </div>'; } ?> 

I accept the array, but I can not cram into the loop, only one item is displayed. If it is possible to shove without an array, all this is in the database, how?

  • and where you have tskil in php? - Gena Ant
  • I cannot compile this cycle. - BozQurd
  • Guys. I have already read all this, I don’t really understand it, but the help of another. - BozQurd
  • and you read it so you understand. Help another "what" or "who", what do you need right now at the moment to do? - Smash
  • create an array fails? - Smash

1 answer 1

for a start, check that print_r($_POST["arr"]) has arrived, and as for me, it would be better to push id purchases id than some html piece. And your code does not consist of any cycle, then so:

 if (isset($_POST['arr'])) { $arr = $_POST['arr']; foreach ($arr as $val) { echo '<div id="iframe"> <div class="shopp"> <span class="label">'.$val.'</span> <span class="mal_sayi">5 kletka</span> <span class="mal_umum_qiymet">цена</span> <span class="endir">скидка</span> <span class="hesab">сумма</span> <br class="all" /> </div><br> </div>'; } } 

I understand this conclusion, and input to the database is a completely different story, and yes, there, too, without a cycle, it is unlikely that you will get an intelligent one.

When a user adds a product to the cart, naturally, your database should have a cart table

 `user_id` `product_id` `values` 

Here every time when he clicks on what-nt product, write in this table the id of this user, product code and quantity.

for example it will look like this:

 `user_id` | `product_id` | `values` 2 | 28 | 3 

one more product added:

 `user_id` | `product_id` | `values` 2 | 28 | 3 2 | 34 | 1 

All for output just output this data. Links it !!!

Accordingly, the user can remove items from the basket.

Of course there are some nuances in terms of the fact that the user must be registered. Simply, there are such stores in which, without registration, you can add goods to the basket, this is already done by the cookie.

  • You are right))) nothing happened with your code either ((. I can send the whole NTML code if you want to help. I’ve been digging Google for 2 days and I can’t solve the problem. I have my code showing an array on alert () I checked And on save.php it only shows one record, the last one added. Would you like some help? If I don’t take your valuable time away, you would help me a lot. Mine has nothing difficult, it’s just very difficult for me . BozQurd 8:55 pm
  • with your code, I get this one here. Warning: Invalid argument for the foreach () in z: \ home \ localhost \ www \ ambar \ save.php on line 12 - BozQurd
  • I have not yet written the code to add to the database, but the ability is not yet ready. if I can get the array through php on the display, then I can also shove it in the database (I think so))) - BozQurd
  • and if the array is serialized and written to the database? Is it not better? - zloctb
  • With our code ... I wrote check variable print_r ($ arr), and then already if there was an array of course there. - Smash