Jump to content

requinix

Administrators
  • Posts

    15,229
  • Joined

  • Last visited

  • Days Won

    427

Everything posted by requinix

  1. If you got int(0) then the echo did output a 0. Somewhere. By the way, if you didn't notice that code always rounds down the minutes. 1:29 will round to 1:15.
  2. As long as you're using POST and not the URL like in your example, $_POST['POSTDATA'] is a string. That's it. All you have to do is stick it in a file with something like file_put_contents.
  3. Exceptions are one way of dealing with problems. If you don't use exceptions then you wouldn't use try/catch. - Exceptions give you a lot of flexibility for dealing with error conditions, but if you don't catch one then your script will crash. - Tracking error codes somewhere (eg, public $errno) are also flexible but if you don't check for them then your application will crash because it doesn't handle error conditions. - Return values are the most common with PHP and force you to handle error conditions, but either they're limited in power or they make your code look crazy because of all the types of things a function can return.
  4. mbstring is the correct way but you have to make sure it knows what character encoding to use. mb_internal_encoding sets the "default" encoding. Otherwise pass the encoding to each of the mbstring functions.
  5. 99% of the time that error means your query failed. Use mysql_error to find out why. And by the way, don't include semicolons in queries. And also by the way, please try to switch to the mysqli or PDO functions. The mysql extension and its mysql_* functions are deprecated because they're old and slow and inefficient.
  6. Excel helps you understand the tabular nature of data, but beyond that forget it. Real databases work differently and are actually capable of doing things like storing large amounts of data in a "cell".
  7. Not sure why the length of the article is an issue... It's a question of requirements. What all do you need? Not included in your list are things like tags/categories and authors - do you want those? The concept of authors (or it sounds for you like simply "users") means all sorts of fun things like users, passwords, permissions... Though a suggestion: combine the date and time into one field. No sense keeping them separate.
  8. So basically you're saying that strstr does exactly what you want but your problem is that it doesn't do exactly what you want? strstr does not do multiple matches, as you've seen. Period. There's no way to magically make it return an array or something. So that means you have to find something else to use with/instead of strstr. In this case that's great because you should be using a different method instead: the DOM. Use DOMDocument to load the HTML and "navigate" to the different elements you want. So unless you want to completely dismiss that idea because you still want to somehow make strstr work, how about posting the HTML you're dealing with and exactly what you're trying to get?
  9. $item->addChild('thumbnail', $path_to_thumbs_dir.'/'.$file);That will add a with a value of $path_to_thumbs_dir/$file. What you want is for it to add a in a specific namespace with an empty value and instead an attribute with the URL. The namespace needs to be declared in your XML. Easiest way is $xml_string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <items xmlns:media="http://search.yahoo.com/mrss/"> </items> XML;Now use addChild() like $thumbnail = $item->addChild('thumbnail', null, 'http://search.yahoo.com/mrss/');Then addAttribute(). $thumbnail->addAttribute('url', $path_to_thumbs_dir.'/'.$file);
  10. Looks right to me. Add a header("Content-Type: application/pdf");before you output the PDF.
  11. The documentation has an example you can check.
  12. FYI in HTML an id is supposed to be unique. That means not using it multiple times like you're currently doing with id="row1Time". Use getElementsByTagName() to get all the spans, then loop over that and grab every one with the right id (or class).
  13. Then it might have something to do with the lots of code you didn't post. So. How about posting everything you have in that file?
  14. Shouldn't you fix the data so it's not duplicated? If you had PHP 5.5 you could use array_column. Otherwise manually build up a new array of only the unique values and loop over that one instead. $munique = array(); foreach ($t as $m) { $munique[$m['url']] = $m; } foreach ($munique as $m):
  15. Loop through $_COOKIE and delete any cookie that matches that name "pattern".
  16. Have you talked with your professor first? S/he is the best person to see if you have questions or problems with your homework as they know you and the assignment much better than we do.
  17. You want to just... drop all the tables? What? Why are there so many and why oh why would you want to delete them?
  18. Yes. That's what "it works for me" means: I did the thing you said that wasn't working but it worked.
  19. Works for me. What's the complete code that isn't working, and how is it not working?
  20. In no particular order, 1. Check for 4,5,6 2. Check that array_count_values() returns 1 item and rank accordingly (the one with 3 quantity, sum / 3, only item in the array, etc.) 3. Check that array_count_values() returns 2 items and rank according to the one with the most instances (ie, 2) 4. Check for 1,2,3 Otherwise reroll.
  21. [edit] Bah, DateTime works too. I like doing the math (if you call a couple subtractions "math") manually. [/edit] Turn ap_add8 into a number any way you want: an array of months or strtotime() are the easiest. Then: Y = end year - start year M = end month - start month if M < 0 then Y = Y - 1 M = M + 12So March 2014 to June 2014 is Y = 2014 - 2014 = 0 M = 6 - 3 = 33 months. June 2014 to March 2015 is Y = 2015 - 2014 = 1 M = 3 - 6 = -3 Y = Y - 1 = 0 M = -3 + 12 = 99 months.
  22. Don't try for some kind of one-line solution. At least not until you have a normal solution working first. Go with the most obvious option: a foreach loop of the (remaining) products in the order, which would itself be inside a foreach of the warehouses.
  23. Apache isn't flexible on the matter, unfortunately.
  24. Forget what I said: it's overly complex and won't give you quite the results you want. And needs some editing. However I do suggest you rearrange your warehouse/stock array into not an array of products and the warehouse quantities, but of warehouses and the products they contain. That should make it easier to get a list of warehouses that provide the quantity to fill an order. array( 9 => array( 35659 => 10, 35699 => 8, 35734 => 10 ), 114 => array( 35659 => 1, 35699 => 0, 35734 => 0 ), 126 => array( 35659 => 0, 35699 => 5, 35734 => 0 ) )Now, the missing part: multiple warehouses.Go through each warehouse in turn and figure out what it can contribute towards the order. For example, with $order = array( 35659 => 10, 35699 => 10 );The first warehouse #9 can do all of #35659 but only eight of #35699. That leaves you with effectively $order = array( 35659 => 0, 35699 => 2 );Then look at the second warehouse. It can't help. However the third has more than enough of #35699 and so you get (perhaps) a result of $filled = array( 9 => array( 35659 => 10, 35699 => 8 ), 126 => array( 35699 => 2 ) );
  25. My brain is a bit fried but I think this will take care of both cases: closest warehouse with all the goods, or closest warehouses that can provide all the goods together. Function takes the order and warehouse stock information. 1. Go through all the warehouses and figure out if any of them can provide all the items in the order. If so, return it 2. Otherwise begin looking at each warehouse individually: - 1. Make a copy of that warehouse's stock information - 2. Subtract from the stock whatever the warehouse can provide to suit the order. Update the order to count the items remaining - 3. Call the function recursively using the modified order and stock information. If the function returns false then also return false - 4. Restore the warehouse's original stock information before continuing 3. Return false since neither of the above algorithms could find a valid combination of warehouses You'll want to deal with an array of warehouses, not just a single ID. And probably make it return not just the warehouses but the items each can fill, which you then use to update their inventories.
×
×
  • 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.