Jump to content

All Activity

This stream auto-updates     

  1. Past hour
  2. requinix

    help with charge formula

    That's the thing. Currently that would not be the case. Because the amount they are credited is calculated as half of $video_cost which is the default price. If they set a higher amount, they still only get half of the default and the site gets the rest. If they set their video with a custom price of half the default price, they would get 100% of the cost and the site would get nothing. Again, half of the default price. You already have an example: the earlier code that was calculating the total for all the videos to play.
  3. Chrisj

    help with charge formula

    Yes, initially for testing purposes "the uploader only gets half the default video price and your site keeps the rest". Regarding "that would mean the uploader is setting a price for you that doesn't affect what they get", if they raise the price they get a bigger 50%, right? Currently, the uploader sets the price but isn't getting 50% "do the same thing when crediting the uploader", can you give me an example, please?
  4. requinix

    help with charge formula

    Yes, if you want to use a $video_play_price variable then it has to be defined somewhere. But don't. Remember how the "video get data" code got the price from $video if set or the default if not? You do the same thing when crediting the uploader. Which means that $uploader_amount variable isn't useful, as it doesn't account for the video price. To be clear, either (a) your existing code has a bug that the uploader only gets half the default video price and your site keeps the rest, or (b) it's not a bug because that's what is supposed to happen... but I doubt this because that would mean the uploader is setting a price for you that doesn't affect what they get. Anyways, if $video->video_play_price is set then it's the price set by the uploader, and if it's not set then the video amount is $video_cost. Do whatever you want with that value, like *0.5 if the uploader gets 50%.
  5. Chrisj

    help with charge formula

    Thanks for your replies. Yes, "$uploader_amount is supposed to be how much the uploader of each video to view gets for the view, and originally is the default video amount minus $charge". The uploader can now optionally change the default price, and I believe it is this line: $amout += $video->video_play_price?$video->video_play_price:$video_cost; I'm trying to get it so when the default price is changed, and a purchase is made, $uploader_amount should then be how much the uploader of each video to view gets for the view, not the default video amount minus $charge, but new video price amount minus $charge. These two attempts were unsuccessful: $uploader_amount = $video_play_price - $charge; $uploader_amount = $amout - $charge; any additional help will be appreciated.
  6. requinix

    help with charge formula

    Maybe it'll help if you can understand what the variables all represent. * $video_cost is the default price for videos, because some videos might have a different amount * $amout is the total cost to play the videos requested, and will use the video amount if there is one instead of the default $video_cost * $charge is how much the site makes (?) per video * $uploader_amount is supposed to be how much the uploader of each video to view gets for the view, and originally is the default video amount minus $charge Like Barand said, the next question is what you want the site to do, and that's a business question not a coding question.
  7. Today
  8. Barand

    help with charge formula

    Without knowing your business model and what these terms mean and how they relate, how do you expect anyone else to tell you what is correct and what isn't? This an accounting problem, not a coding problem.
  9. Chrisj

    help with charge formula

    This code, that I didn't write, but am trying to modify, generates the cost of a video purchase. One line (line 32) is a formula , I believe for setting a purchase price amount: $amout += $video->video_play_price?$video->video_play_price:$video_cost; Another line (line 50) is a formula for deducting to create another amount: $uploader_amount = $video_cost - $charge; I think line 50 is correct except for I don't think $video_cost in the final price, but I'm no expert at reading this code. I tried this without success: $uploader_amount = $video_play_price - $charge; Here is the full code, any help with line 50, will be appreciated. <?php if (IS_LOGGED == false) { $data = array('status' => 400, 'error' => 'Not logged in'); echo json_encode($data); exit(); } if (!empty($_POST['id'])) { if (!is_array($_POST['id'])) { $id_array[] = $_POST['id']; } else { $id_array = $_POST['id']; } // get cost video $db->where('name', 'video_play_price'); $db_cost = $db->getOne('config'); $video_cost = (float)$db_cost->value; $count_video = count($id_array); $user_id = $user->id; $wallet = (float)str_replace(',', '', $user->wallet); $amout = 0; foreach ($id_array as $id) { $video_id = (int)PT_Secure($id); // get video data $video = $db->where('id', $id)->getOne(T_VIDEOS); $amout += $video->video_play_price?$video->video_play_price:$video_cost; } // $amout = $video_cost * $count_video; $charge = ( $video_cost *0.50 ); if ($wallet >= $amout) { $new_wallet = (string)($wallet - $amout); $db->startTransaction(); $inserted_records = 0; foreach ($id_array as $id) { $video_id = (int)PT_Secure($id); $uploader_amount = $video_cost - $charge; // get video data $video = $db->where('id', $id)->getOne(T_VIDEOS); // add data to paid table $insert_buy = $db->insert('u_paid_videos', [ 'id_user' => $user_id, 'id_video' => $video_id, 'session_key' => $_SESSION['session_key'], 'video_play_price' => (string)$video_cost, 'video_title' => $video->title, 'user_id_uploaded' => $video->user_id, //'up_credit'=>$video_cost, 'up_credit'=>$uploader_amount, ]); if ($insert_buy) { $inserted_records++; } //add wallet users' video $userwallet = $db->where('id', $video->user_id)->getOne(T_USERS); //$videouserwallet = $userwallet->wallet+$video_cost; $videouserwallet = $userwallet->wallet+$uploader_amount; $db->where('id', $video->user_id); $update_wallet = $db->update(T_USERS, [ // 'wallet' => $videouserwallet, 'wallet' => number_format($videouserwallet, 2, '.', ''), ]); } $db->where('id', $user_id); $update_wallet = $db->update(T_USERS, [ 'wallet' => $new_wallet, ]); if (($inserted_records == $count_video) && $update_wallet) { $db->commit(); echo json_encode([ 'status' => 200 ]); exit(); } else { $db->rollback(); echo json_encode([ 'status' => 400, 'error' => 'Buy process error' ]); exit(); } } else { echo json_encode([ 'status' => 400, 'error_num' => 1, 'error' => 'Not enough money' ]); exit(); } } else { echo json_encode([ 'status' => 400, 'error' => 'Bad Request, Invalid or missing parameter' ]); exit(); }
  10. Barand

    Update MySQL table from 2 or 3 other tables

    How many people, places times and roles? What are the constraints re number of people in one place at the same time? And yes, as @requinix
  11. requinix

    Update MySQL table from 2 or 3 other tables

    Your description would probably make a lot more sense if we could see the table structures and some sample data.
  12. Dears, I really need your help. I have a project for automatically assign people to exams locations and timings. I have 3 tables, 1 containing places, 1 timings, 1 people and their roles. I want a query that assign 1 person from role 1 and 1 person from role 2 with a timing and a place and to do this randomly and equally . So, it will repeat the person only if all people are assigned before. I really appreciate your help. This is as far as I could research ... this example UPDATE member m1 JOIN ( select id, floor(1+rand()*10) as rnd from member ) m2 on m1.id=m2.id JOIN names n on n.id = m2.rnd SET m1.name=n.name But this doesn't do all, please accept my great apology. Mahmoud
  13. Barand

    fatal error: call to a member function

    Yeah, there are a couple of things wrong with the line that does contain the error The variable doesn't exist, it should be referenced via $this The call shouldn't be there at all. One certainly shouldn't close the connection after each query and it's seldon necessary ever to close a connection. It is done automatically when the script ends.
  14. requinix

    fatal error: call to a member function

    It's the title: call to a member function on a non-object. The sad thing is that it should even point out the exact line where the problem is, which is just about as far as anyone can go to saying what the problem is without actually stating it.
  15. Barand

    fatal error: call to a member function

    Talking of error messages, after three hundred posts you should have learned that is not sufficient just to say you have "an error". Provide us with the actual error message - they are provided to give clues about what the error might be.
  16. requinix

    fatal error: call to a member function

    I don't suppose you mis-copied the bit of code about where the error message comes from?
  17. requinix

    Setting deep object properties

    Oh, so the problem is that you don't know if ->a, ->b, or ->c are defined. I would deal with the data as an array and not an object, and array_replace_recursive.
  18. NotionCommotion

    Setting deep object properties

    It's not the detection which I have an issue with but how to set them. Unlike arrays, I cannot just use $config->a->b->c->x=123 if a, b, or c is not set. Ah yeah, I do remember (now) that isset() unlike array_key_exists() will return false upon null. Thanks
  19. requinix

    Setting deep object properties

    Something cleaner? isset($config->a->b->c->x) || $config->a->b->c->x = 321; isset($config->a->b->c->y) || $config->a->b->c->y = 321; Remember that isset() also covers the case where the value exists but is null. It's cool to have something that can arbitrarily set properties, but make sure what you have to give up in return is worth it. Here, I don't think you're gaining nearly enough for the sacrifice in readability.
  20. NotionCommotion

    Setting deep object properties

    Thanks ginerjm. Good point, however, it is not my design (the objects are the json objects used to configure Highcharts) and realistically they will only be 3 or 4 deep max . Any recommendations on the best approach? Thanks
  21. ginerjm

    Setting deep object properties

    did you ever consider that having a structure so very deep is possibly a poor design?
  22. NotionCommotion

    Setting deep object properties

    I need to set a deep property if it is undefined or NULL such as shown below: function setProperty($value, stdClass $config, $p1, $p2, $p3, $p4) { if(!isset($config->$p1->$p2->$p3->$p4) || is_null($config->$p1->$p2->$p3->$p4)) { $config->$p1->$p2->$p3->$p4=$value; } } $config=json_decode(json_encode(['a'=>['b'=>['c'=>['x'=>null, 'y'=>123]], 'x'=>123],'x'=>['x'=>123], 'x'=>123])); setProperty(321, $config, 'a','b','c','x'); setProperty(321, $config, 'a','b','c','y'); But I wish the function to work regardless of property depth and came up with the following. Recommendations for a cleaner way? Maybe I should be working with arrays and array_merge_recursive()? function setProperty($value, stdClass $config, array $properties) { $property=array_shift($properties); if(!count($properties)){ if(!isset($config->$property) || is_null($config->$property)) { $config->$property=$value; } } else { if(empty($config->$property) || !is_object($config->$property)) { $config->$property=new \stdClass(); } setProperty($value, $config->$property, $properties); } } $config=json_decode(json_encode(['a'=>['b'=>['c'=>['x'=>null, 'y'=>123]], 'x'=>123],'x'=>['x'=>123], 'x'=>123])); setProperty(321, $config, ['a','b','c','x']); setProperty(321, $config, ['a','b','c','y']);
  23. CyberShot

    fatal error: call to a member function

    I see in my post that the braces are messed up. I just didn't copy the code correctly. They are not messed up in the class
  24. benanamen

    fatal error: call to a member function

    Your curly braces are messed up. If you used a proper IDE you would see these basic problems. There are other issues as well including trying to call a private property. Overall, this is a pretty bad Class. I will let the other members comment further. EDIT: couple more comments: The connection parrameters should not be hard coded in the class. You should not be outputting internal system errors to the users. The querys should be passed, not hard coded nor the HTML, the connection should do just that, with the CRUD operations in another class. The path you are on will require you to always have to edit the class every time you use it. Think "Single Responsibility".
  25. I am trying to create a class and I ran into a problem. The connect function is returning a fatal error on the line below and I can't figure out the issue. $result = $this->conn->query("SELECT unit FROM address"); class database { private $server = "localhost"; private $db_user = "my user"; private $db_pass = "my pass"; private $db_name = "my database"; private $conn; private $result = array(); function connect(){ // Create connection $this->conn = new mysqli($this->server, $this->db_user, $this->db_pass, $this->db_name); if ($this->conn->connect_error) { echo "Not connected, error: " . $mysqli_connection->connect_error; } else { //echo "Connected."; return $this->conn; } public function displayHeader(){ $result = $this->conn->query("SELECT unit FROM address"); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo '<li>' . $row["unit"] . '</li>'; } } else { echo "0 results"; } $conn->close(); } } }
  26. Yesterday
  27. connecting atom/ on linux with GIT and github, dear experts - good day dear phpfreaks today i have a question regarding connecting atom/ on linux with GIT and github, ive heard that this would be but very simple from the command line and linux… Set your email: https://help.github.com/articles/setting-your-commit-email-address-in-git/ After uploading keys, test your ssh connection: https://help.github.com/articles/testing-your-ssh-connection/ Switch repo to use ssh rather than https: https://help.github.com/articles/changing-a-remote-s-url/#switching-remote-urls-from-https-to-ssh but if i look at my atom editor i have the options of connect with GIT connect with GITHub well whats the difference here betweeen git and github!? why cannot add some commits while i see the git with create detached commend - nothing happens here
  28. kicken

    How to clear bookmarks In PhpStorm 2017.2.4

    Just hit your Delete key while you have them highlighted in the bookmarks window.
  1. Load more activity
  • Newsletter

    Want to keep up to date with all our latest news and information?

    Sign Up
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.