Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep Power
    0
    Originally Posted by Jacques1
    Note that he's crossposted his thread around the whole f*cking internet, so the question probably has been answered 10 times already.

    Don't waste your time repeating other peoples' replies.
    I dont know why you feel so angry at me. I have not posted it on the 'whole internet'. I have only posted this question on here stackoverflow and another forum. I wanted to see what ways I can best implement my problem. Sorry if this has offended you but I dont know what I have done wrong.
  2. #17
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,920
    Rep Power
    1045
    It's just rude and stupid to copy and paste the same text and let four different forums work on it at the same time without telling anybody about it. This means a lot of effort is wasted with redundant answers.

    I understand that you want as many answers as quickly as possible. And since it's for free and takes no more than a few clicks, why not post it in four different forums. The problem is that there are actual people on the other end, not bots or something.

    Just think about it for a second: Somebody asks you for help, and you spend quite some time and thoughts on the problem. When you get back with the solution, the person tells you: "Thanks, but I gave the problem to 10 other people and already got the answer." Wouldn't you find that a bit ... frustrating?

    The reason why we help is because we think it's useful. Reenacting a discussion at stackoverflow is not useful, so it's very annoying for the people trying to help you -- even if some replies might contain new info within all the redundant stuff.

    When you feel the need to lead four discussions at the same time, at least tell people about the other forums. This allows everybody to decide whether or not he/she wants to participate in that mass discussion or not.

    You can find further information about crossposting in pretty much any netiquette.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep Power
    0
    Ok, I am very sorry you feel this way. I do respect everyones help a great amount and I never would disrespect anyones answers or effort to help. I know they are not bots and are people there helping. It was not a matter of clicking just because it is free. I have spent a lot of time myself on it but I am not getting the results I need hence, I thought I'd ask on other places to see what else responses I can get.

    I did not once post the same question straight away on another site/forum. I waited and saw what responses I got back and then as I could still not solve the problem I asked on different forum and stackoverflow.

    If you read my replies on stackoverflow I did mention that I have asked this question in more detail on this link (this forum's link) So, I did reference it to this website that I have asked the same question. However, on here I have explained it a bit more detail.

    I do appreciate what you mean and I totally respect that. Like you stated, I wanted to see in what ways I can best implement this as I have spent time and effort on it. I in no way want to waste people's time or make them feel bad in anyway especially as they are helping me to answer the question.

    Once, again I do apologise if I have made you or anyone else feel bad about this and I will bare it in mind if I do get stuck again and need to seek help/advice.

    Comments on this post

    • Jacques1 agrees
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep Power
    0
    Originally Posted by gw1500se
    OK, so you don't really mean you want to update the database. You want to keep reading sorted rows until the quantity is met. You need to keep a counter initialized before the loop. Use that counter for your loop not the row data. Untested:
    PHP Code:
     $quantity=0;
     
    $price=0;
     while (
    $rows1 mysql_fetch_assoc($queryQuantity2)){
            if(
    $quantity>=$quantityRequested){
                echo 
    "$price<br />";
                break;
            }else{
              echo 
    $rows1['FName'];
              echo 
    $rows1['NameProduct'];
              echo 
    $rows1['Quantity'];
              echo 
    $rows1['Price']; 
              
    $quantity+=$rows1['Quantity'];
              
    $price+=$rows1['Price'];
       }

    Hi, I have been trying to work on your solution however, I am still getting stuck. (Btw, I would need to update the database since X quantity would be reduced when 'committed')

    I have my quantity and price counter like you stated. Then checking if the quantity variable is >= the $requestedquantity(the requested quantity has stored the quantity that has been required.).
    I use the if loop you said and output the price once the quantity has been met.

    However, the problem I am having is in the else block.
    As you know here is the sellers table:

    Code:
     FName   |   ProductName    |     Description                 |  Quantity  |   Price
            --------------------------------------------------------------------------
         compny1          Apple            royal apples fm appleco.      5.0          5.00
            daz            Apple              sweet apples              6.0          5.50
        company2         Apple            Apples yum                     8.0          9.00
    so the quantity variable checks row 1. See's $quantity is not > $quantity requested ... So prints row one and updates database.
    Next what it needs to do is do the $requestedquantity-$quantity (i.e. how much has more is needed.). This then would show 5kg is more needed. The second row is selling 6.0. So it would have to then add 5.0 from row 2(daz). Hence now it has been met so the total price of £10.50 is displayed. And the order's table shows 2 rows i.e.
    Code:
    orderNo   seller           product    quantity    price   customerid
       1         compny1       apple           5.0       5.00        3
       2         daz           apple           5.0       5.50        3
    The actual sellers table (orginal table) is only updated with the reduced quantities once both the buy and seller has 'commited' to the trade.

    Is there anyway you can help/guide me on how to solve this issue please?

    Thank you.
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    You shouldn't update the database until the commit. Keep track of how much you need to take per vendor. When the commit is processed use that data to update the database then and only then.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #21
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep Power
    0
    Originally Posted by gw1500se
    You shouldn't update the database until the commit. Keep track of how much you need to take per vendor. When the commit is processed use that data to update the database then and only then.
    Okay I see what you mean.

    What I'm thinking is this now .. Pseudo code:

    PHP Code:
    while ($rows1 mysql_fetch_assoc($queryQuantity2)){//check all matches
    $price=0.0;
    $currentquantity=0.0;
    $difference=0.0

    if($currentquantity=$requestedquantity){
          echo 
    $price;
          break;
    }else if(
    $currentquantity $requestedquantity){
              echo 
    $rows1['FName']; 
              echo 
    $rows1['NameProduct']; 
              echo 
    $rows1['Quantity']; 
              echo 
    $rows1['Price'];
             
             
    $currentquantity +=$rows1['Quantity']; 
             
    $price += $rows1['Price']; 
             
    $difference $currentquantity $requestedquantity;// so this is used to see how much more is still needed.  

    // Now the problem is where do I store these records? and how to display them to the logged in user?
    // I mean can I have like say 'tempOrders' table where it stores the matching data? something like..

    mysql_query("INSERT INTO `tempOrders` VALUES ($rows1['FName'],
    $rows1['ProductName'],
    $//Which quantity variable would I use here? would it be the 
    $difference right?
    $rows1['Price'],
    $customerid//from logged in session )")
    }


    How would you best suggest I should do this? Because if I can show the matches in a 'tempOrders' table it shows potential best matches however is not a full order yet since it has not been committed.

    What would you recommend and suggest
  12. #22
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep Power
    0
    oh and this is probabily a stupid question but when I declare the price, quantity and difference variables does it make a difference if I initialise them to 0.0

    i.e. $price = 0.0
    or $price=0

    Since in my DB I have listed $price as a double with 2 digits after decimal point.

    Thank you.
  14. #23
  15. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    PHP determines on its own, variable typing. You can initialize it to integer 0 and when a float is used, it will convert to float automatically. This can sometimes lead to unintended results so you need to be careful with variable usage.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #24
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep Power
    0
    Originally Posted by gw1500se
    PHP determines on its own, variable typing. You can initialize it to integer 0 and when a float is used, it will convert to float automatically. This can sometimes lead to unintended results so you need to be careful with variable usage.
    Ahh thats cool thanks. Does my pseudo code look correct on what I am doing?
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo