ZackTim Posted February 3, 2019 Share Posted February 3, 2019 Hello, I have an array that display transfers, each transfer can be refunded, once done, it will allow you to re-send it back with the help of "Repay" Button, check screenshot. You will notice that at the top,there are 2 refunded transfers, each time a transfer is refunded, a repay button will appear then it will generate a new line with same transfer, in this case transfers from seller1@domain are generated 3 times, (2 times refunded and repaid back) I'm trying to find a way to list only unique transfers instead of these duplicated enteries, I tried array_unique but it will throw an error : Notice: Array to String conversion... Here is my code: if ($all_transfers_details) { if (count($all_transfers_details)>1) { $all_transfers_details = array_unique($all_transfers_details); } If I change the count like >20 or even >100 the error is not thrown, but it won't hide those previously refunded entries. Quote Link to comment Share on other sites More sharing options...
requinix Posted February 3, 2019 Share Posted February 3, 2019 Remember we have no idea what $all_transfers_details is. array_unique() won't work on multidimensional arrays. Is that what you're working with? If the problem is that you need to remove some additional lines that were added, wouldn't the best solution be to make it not add those lines? Or maybe it's to add the new line but also remove the old one? Quote Link to comment Share on other sites More sharing options...
maxxd Posted February 3, 2019 Share Posted February 3, 2019 This sounds like a data gathering issue. I assume the data's coming from a database and includes a transaction ID and transaction type, yes? Would it be easier to pull transaction type sale without a corresponding refund transaction type - I'm sure there's additional business logic to be considered, but it seems to me it'd be easier than pulling everything and culling data you don't want from that. Quote Link to comment Share on other sites More sharing options...
ZackTim Posted February 3, 2019 Author Share Posted February 3, 2019 Hello guys, thanks for your response. Remember we have no idea what $all_transfers_details is. => It's an array that will list all transfers made by admin back to sellers' wallets. array_unique() won't work on multidimensional arrays. Is that what you're working with? => So which function will hide those duplicated entries? wouldn't the best solution be to make it not add those lines? Or maybe it's to add the new line but also remove the old one? => Correct, but how, it works with only 1 transfer, once you refund it, it will only show 1 entry but if there is multiple transfers, it won't work, my code did this perfectly but as I said only for the first transfer, here is the code: $all_transfers_details = array(0=>array_pop($all_transfers_details)); Anyway to influence this code to be applied on all transfers? I assume the data's coming from a database and includes a transaction ID and transaction type, yes? Correct, it's pulled from the DB for sure. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 3, 2019 Share Posted February 3, 2019 If it is already stored nicely in a db, why try and re-create the wheel with an array? Modify your table structure to add a couple of needed fields that you are trying to utilize in an array and work with that. Quote Link to comment Share on other sites More sharing options...
ZackTim Posted February 3, 2019 Author Share Posted February 3, 2019 (edited) Hello, @ginerjm I can't modify any table because each table has a connection with another one, modifying will make things worse. When you click Refund, it will take the transfer out of the seller's wallet back to admin's wallet, now you decided to repay the seller, you click, and you submit. Since a new transfer created, a new entry will be visible in case "again" you wanted to refund it "for some reasons". But I still need to "Hide" those unwanted transfers, If you tried to Repay a "Refunded" transfer, it will just work fine. Anyway to filter the duplication by using Order Id ? Edited February 3, 2019 by ZackTim Quote Link to comment Share on other sites More sharing options...
maxxd Posted February 3, 2019 Share Posted February 3, 2019 1 hour ago, ZackTim said: Anyway to filter the duplication by using Order Id ? Chances are very good, yes. However, it's going to depend on how the tables are structured. I'm assuming there's a way to tell refunds from sales in your database - use that as your JOIN criteria. So, basically, 15 hours ago, maxxd said: pull transaction type sale without a corresponding refund transaction type when joined on transaction ID. Quote Link to comment Share on other sites More sharing options...
ZackTim Posted February 3, 2019 Author Share Posted February 3, 2019 Thanks @maxxd for your input, however, if you pulled transfers which are not refunded or [ $isRefunded = 0 ] once you hit Refund, it won't show you the refunded transfer to do the repay functionality, that in case if I only want to list transfers that are not refunded but in the other hand, I still need to see the refunded entry so I can do "Repay" and once done, that will disappear and another entry will be generated for the same transfer I originally refunded, you might read this and take a look at the screenshot I attached in my first post. Quote Link to comment Share on other sites More sharing options...
benanamen Posted February 3, 2019 Share Posted February 3, 2019 @ZackTim, post an SQL dump of your DB schema with a few sample records so we can see what your working with. Quote Link to comment Share on other sites More sharing options...
maxxd Posted February 3, 2019 Share Posted February 3, 2019 I'm totally confused - you say in the OP that a problem is that " it won't hide those previously refunded entries. ", but you need to see the previously refunded entries? I'm not getting it, so I'm gonna bow out in an attempt to lower the signal-to-noise ratio... Quote Link to comment Share on other sites More sharing options...
ZackTim Posted February 3, 2019 Author Share Posted February 3, 2019 @maxxd Forgive me for the confusion, I will explain, take a look at Screenshot1 and Screenshot2. Screenshot1 will show a transfer, Let's do the Refund. ScreenShot2, now we did the refund, do you see how it looks? Imagine this, If you clicked on Refund then the entry is hidden, how would I Repay back? Once I "Repay" it should then Change from "Refunded - Repay" To "Refund", now, this situation works fine if you have only 1 transfer, if you have more than 1, then it will display the previous ones. Is it possible to use array_diff and filter the entries by Order Id Quote Link to comment Share on other sites More sharing options...
ZackTim Posted February 3, 2019 Author Share Posted February 3, 2019 What I'm trying to say is: If a Refunded Transfer is Repaid back, then it should be hidden because there will be a new one generated with same Order Id Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.