Jump to content

TOA

Members
  • Posts

    623
  • Joined

  • Last visited

Everything posted by TOA

  1. Ok, as far as I can tell, this does it foreach( $currency as $name => $value ) { $num = 0; // How many of the given currency to give if ($currency[$name]['count'] > $num) { if( $change >= $currency[$name]['value'] ) { // Check if change still to be given is more than the currency while( $change >= $currency[$name]['value']) { // Loop through until it's less $num++; // Increase the amount of currency to give $change -= $currency[$name]['value']; // subtract value from currency } } } $changeArray[$name] = $num; // Add the amount to our change array } Let me know if anyone sees any flagrant issues Ok, nevermind, I already encountered an issue. Use 1 Toonie and 8 loonies for counts and it gets some weird results. GDI!
  2. So I have a version of this code working with a multidimensional array that adds a "count". So essentially, it tells me how many of each currency I have to work with. I think I just need to know where in the first foreach loop I need to check for the count and if they don't have any more of that currency, to go on to the next smaller denomination. Hope that makes sense <?php $currency = array( '20 Bill' => array('value'=>2000, 'count' => 0), '10 Bill' => array('value'=>1000, 'count' => 0), '5 Bill' => array('value'=>500, 'count' => 0), 'Toonie' => array('value'=>200, 'count' => 0),// I'm Canadian 'Loonie' => array('value'=>100, 'count' => 0), 'Quarter' => array('value'=>25, 'count' => 6), 'Dime' => array('value'=>10, 'count' => 3), 'Nickel' => array('value'=>5, 'count' => 5), 'Penny' => array('value'=>1, 'count' => 10)); $cost = 11.07; $cashGiven = 20.00; $change = ($cashGiven*100) - ($cost*100); $changeArray = array(); // Will store the change to give. echo 'Cost was: '.$cost.'<br>'; echo 'Amount given was: '.$cashGiven.'<br>'; echo 'Change was: '.($change/100).'<br>'; // Loop through our currency, greatest to least foreach( $currency as $name => $value ) { $num = 0; // How many of the given currency to give if( $change >= $currency[$name]['value'] ) { // Check if change still to be given is more than the currency while( $change >= $currency[$name]['value']) { // Loop through until it's less $num++; // Increase the amount of currency to give $change -= $currency[$name]['value']; // subtract value from currency } } $changeArray[$name] = $num; // Add the amount to our change array } echo 'Currency to give back:<br>'; // Loop through the change we need to give foreach( $changeArray as $name => $amount ) { if( $amount ) {// Make sure amount isn't 0 echo $amount.' '.$name; echo ($amount > 1 ? 's' : '').'<br>'; // if $amount > 1 add an s to the end of $name } } ?>
  3. Let me clarify..I need to check for what the "register" would have. Say the purchase is 45 and they give me a fifty. What this script does (correctly) is to return a five. What if I don't have a five? So I need to throw another dimension into $currency that has the number of each that I have to return. Hope that makes sense.
  4. How could I get this script to use what the person has in their pocket? I've tried a bunch of things and could post about 9 butchered versions, but I thought it might be easier to start from square one to get help.
  5. TOA

    php post

    That's what I saw at first too. @OP-does anything get entered into the database?
  6. TOA

    php post

    @Jacbey: it depends on how he's using it. He could be checking for a "true" boolean value, or to see if it exists. I suspect he's not though so @OP, maybe you can clarify? Take this example: if ($title) { echo "Set or true"; } else { echo "Not set or not true"; } outputs "Not set or not true" Yet this: $title = "anything"; if ($title) { echo "Set or true"; } else { echo "Not set or not true"; } will output "set or true"
  7. aha ok. however when i put the code to this loop: foreach ($_FILES["image"]["error"] as $key => $error) {} and make the name of the box with [] still doesnt work.. The table i use its normal one that contains 4 columns for the picture . Can you show all your relevant code?
  8. No extra fields would be needed if I understand you correctly. Each image would be stored as a new record. Depends on your table structure though. If you can post that it might help To echo, just loop through the directory where they're stored and display them
  9. TOA

    php post

    Does anything get entered into the db?
  10. Gotcha. Here's from the manual on how to do it
  11. Let's just say I'm feeling generous Just telling you. Not everyone would help with that approach. Notice he hasn't posted again? Anyway... make your form element an array, and add a loop around the processing for each file in the input array
  12. LMAO Ok. Lets see how much help you get telling people they have to help you. BTW..you could use an array to store the multiple files
  13. Actually, no. All staff, gurus, etc are volunteers if I'm not mistaken.
  14. Oh snap! I read "text" for the input type for some reason..my bad
  15. So Zane is right, the file doesn't exist because that isn't what you described before. Your form takes a string and tries to open a file with that name. If youre allowing an upload, you need to handle it from it's temp location. Read this on handling file uploads
  16. Don't give up so easily. Are your php file and the csv in the same folder? If not, then you need to add the path to $handle. That's all Zane's saying (I think, not trying to put words in his mouth).
  17. You just want your results numbered? You could use a variable to increment with every loop, or use an <ol> tag
  18. A cron job runs a script. You would need to write the script to send the emails, and set up a cron job to run it. Most of the time this is done in an admin dashboard, but can be done in command line also.
  19. Alright. Did you echo all the variables to see they hold what they should? Maybe you should post more code; there's no reason it shouldn't work that I can see if what you say is true.
  20. Well, acording to this script, $to isn't actually set to anything because either is $Email_address. Also, your check is almost right. The way you have it would send two emails if it was working. It can be one of two ways: if (mail($to, $subject, $message, $headers)) { //error } else { //success } in which case you don't need the first mail() call. Otherwise you can do it like this: $check = mail($to, $subject, $message, $headers) if (!$check) { //error } else { //success }
  21. I think it's the $userid variable in the sql. That should be a field name, not the value. Try id, assuming usr holds an id in the table. <li>Username: <?php /*Displays Logged in Users Name*/ echo $userid;?></li> <li>Test Drop Down: <?php $query="SELECT name,id FROM PRO WHERE name NOT IN (SELECT golfer FROM weekly_picks) AND id NOT IN (SELECT usr FROM weekly_picks)";
  22. Shafted! All because he kept beating me to the punch Kidding. Glad it helped
×
×
  • Create New...

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.