Jump to content

Barand

Moderators
  • Posts

    24,337
  • Joined

  • Last visited

  • Days Won

    795

Posts posted by Barand

  1. 'til now
    they have been mathematical
    so here's one
    that's purely grammatical

    Q4

    Correctly punctuate this sentence so that it makes sense

    • the two boys had written very similar essays but peter where paul had had had had had had had had had had been preferred by the teacher
  2. Welll done. I knew you'd do it.

    Hint for others:

    Spoiler
    1. walrus = 7
    2. widgeon = 21
    3. wombat = 11
    4. weasel = 20
    5. wolverine = 28
    Spoiler

    Solution:

    1) a + u = 7
    2) e + i + o = 21
    3) a + o = 11
    4) a + 2e = 20
    5) 2e + i + o = 28

    Subtracting #2 from #5 we get e = 7
    Substituting this value in #4
        a + 14 = 20
        a = 6
    From #3 we now have
        6 + o = 11
        o = 5
    From #1
        6 + u = 7
        u = 1
    From #2
        7 + i + 5 = 21
        i = 9
        
    Therefore woodchuck = 2o + u = 11

     

  3. Your foreach() loop expects several items and that each will be put into $row as you loop through.

    But get(cart_item) only returns a single item so when you use foreach() you are looping through its properties

    Try

    $row = Session::get("cart_item");
    echo <<<ITEM
                      <tr>
                        <td width="70"><center>{$row['ItemCode']}</center></td>
                        <td>{$row['ItemDesc']}</td>
                        <td width="70"><center>{$row['ItemQty']}</center></td>
                        <td width="70"><center>{$row['ItemAmount']}</center></td>
                        <td width="70"><center>{$row['ItemTotalAmount']}</center></td>
                      </tr>
    ITEM;

     

  4. Are you saying that if you

    foreach(Session::get("cart_item") as $row) {
        print_r($row);
    }
                    

    then you get...

     

    22 minutes ago, Andy2024 said:
    Array ( [ItemDesc] => JOULE 300L AERO COIL [ItemCode] => 118710 [ItemQty] => 1 [price] => 4764.54 [ItemTotalAmount] => 4764.54

    for each item?

  5. For anyone else out there, feel free to join in. Meanwhile...

    Q3

    Some animals are gathered in the forest having a midwinter party, all seated around a fire.  When the fire starts to die down they all move off to gather more wood.
    The walrus manages to gather 7 twigs and throw them on the fire, the widgeon throws on 21 twigs, the wombat 11 twigs, the weasel 20 twigs and the wolverine throws on 28 twigs.
    How much wood would a woodchuck chuck if a woodchuck would chuck wood?

  6. I took the integration / volume of rotation route and came up with the solution.

    Spoiler

    When I passed the question to my friend (who, incidentally, has a PhD in Mathematics) he thought for a few seconds then said "36 pi. Consider the case where the diameter of the hole is zero".

    In that case it simply becomes the volume of a 6cm diameter sphere. Doh!

     

  7. For some reason that number has stuck in memory for for the last 58 years, which is strange as I sometimes struggle to recall my phone number (the one I never dial). On those occasions when I have doubted my recall I just use my calculator to divide 30 by 17 (which contains the answer as a recurring sequence) to verify.

    * * * * *

    Anyone up for another (simpler) one?

    You have a solid wooden sphere and drill a vertical hole centrally through it.

    sphere_with_hole.JPG.6338ab50ff8121728ee83820f1b5cea8.JPG

    The resulting object is now 6cm high. What is the volume remaining?

  8. If you miss a semi-colon then no code runs because of the syntax error. It doesn't get as far as any errors that may occur. (set "diplay_startup_errors" ON in your php.ini file to be informed of any syntax errors.

    Post your error messages - it helps us.

  9. The boards are quiet at the moment so I thought you might glad of something to exercise your little grey cells. When I was 17 I borrowed a maths book from the local library and in it was this simple question (posed by the speaker at a Royal Mathematical Society dinner)...

    • What is the smallest integer that when the first digit is moved to the end, the new number is exactly one and a half times the original?
  10. 8 minutes ago, oz11 said:

    Can it not be done with iindex++ and function parameters?

    Maybe. I have no way of knowing what you intend to do with the index and the function parameters.

    Two things to bear in mind

    1. ID values must be unique - you cant have several inputs all with the id="comment_text2"
    2. When you define an event listener on page load, it is only attached to elements that exist when the page has loaded and not to elements you add dynamically.
  11. I like to use data attribute on these occasions.

    NOTE: use a class name for the selects and another for the inputs. Don't use ids.

    Maintain a count of how many comments the user adds and increment each time they add a new one.

    When creating a new select and input, give them both a data-id attribute with the value of the count.

    When emoji selected, get the value of the select's data-id. Look for the input with the same data_id and insert the emoji.

    • Thanks 1
  12. I agree with mac_gyver except for the use of OR in the WHERE clause.

    Consider this product table...

    +------------+-------------------------+
    | product_id | description             |
    +------------+-------------------------+
    | 1          | Black mamba             |
    | 2          | Fireball XL5            |
    | 3          | Single coat black paint |
    | 4          | Coat of many colours    |
    | 5          | Black coat XL           |
    | 6          | Not of interest         |
    +------------+-------------------------+

    Code...

        $search = 'coat black xl';
        $params = array_map(fn($v)=>"%$v%" , explode(' ', $search));
        
        $q1 = "SELECT description FROM product          -- search query using OR
               WHERE description LIKE ?
                  OR description LIKE ?
                  OR description LIKE ?
              ";
              
        $q2 = "SELECT description FROM product          -- search query using AND
               WHERE description LIKE ?
                 AND description LIKE ?
                 AND description LIKE ?
              ";

    Results...

    Results using OR
    +-------------------------+
    | description             |
    +-------------------------+
    | Black mamba             |
    | Fireball XL5            |
    | Single coat black paint |
    | Coat of many colours    |
    | Black coat XL           |
    +-------------------------+
    
    Results using AND
    +---------------+
    | description   |
    +---------------+
    | Black coat XL |
    +---------------+

    A couple of other options are open to you

    1. FULLTEXT
      Add fulltext index on description and
      $q3 = "SELECT description
                            , MATCH(description) AGAINST('coat black xl') as relevance
                       FROM product
                       WHERE MATCH(description) AGAINST('coat black xl')
                       ORDER BY relevance DESC
                      " ;
                      +-------------------------+-------------------+
                      | description             | relevance         |
                      +-------------------------+-------------------+
                      | Black coat XL           | 0.18123811483383  |
                      | Single coat black paint | 0.18123811483383  |
                      | Coat of many colours    | 0.090619057416916 |
                      | Black mamba             | 0.090619057416916 |
                      +-------------------------+-------------------+

      NOTE: with fulltext, words of 3 or less characters (eg "XL") are ignored.

    2. Use separate columns for category, colour and size and search on those.
    • Like 1
  13. 29 minutes ago, phppup said:

    Tinkering with the value, even as a variable going into a database is essentially unnecessary?

    If it is going into a database then you should be using prepared queries which will guard against SQL injection.

    31 minutes ago, phppup said:

    you failed to offer any constructive alternative

    Mozilla Developer Network (MDN)

×
×
  • 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.