PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old March 3rd, 2013, 04:52 PM
dazase1 dazase1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 21 dazase1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 45 m 58 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
  #17  
Old March 3rd, 2013, 05:15 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,881 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 8 h 22 m
Reputation Power: 813
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.

Reply With Quote
  #18  
Old March 3rd, 2013, 05:31 PM
dazase1 dazase1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 21 dazase1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 45 m 58 sec
Reputation 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!

Reply With Quote
  #19  
Old March 4th, 2013, 03:30 PM
dazase1 dazase1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 21 dazase1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 45 m 58 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
  #20  
Old March 4th, 2013, 03:54 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
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.

Reply With Quote
  #21  
Old March 4th, 2013, 04:17 PM
dazase1 dazase1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 21 dazase1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 45 m 58 sec
Reputation Power: 0
Quote:
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

Reply With Quote
  #22  
Old March 4th, 2013, 04:32 PM
dazase1 dazase1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 21 dazase1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 45 m 58 sec
Reputation 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.

Reply With Quote
  #23  
Old March 5th, 2013, 07:01 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
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.

Reply With Quote
  #24  
Old March 5th, 2013, 07:03 AM
dazase1 dazase1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 21 dazase1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 45 m 58 sec
Reputation Power: 0
Quote:
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Obtain data from SQL DB until condition has been met

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap