Jump to content

Barand

Moderators
  • Posts

    24,613
  • Joined

  • Last visited

  • Days Won

    834

Everything posted by Barand

  1. Plan B Use this line instead of the two I gave earlier $combinations = array_values(array_filter( $combinations, function($v) { return count($v) == count(array_unique($v)); }));
  2. This is when reading the manual comes in useful php.net/array_values php.net/array_unique php.net/sort
  3. You could add these two lines foreach ($combinations as $k => &$a) sort($a); $combinations = array_values(array_unique($combinations, SORT_REGULAR));
  4. Alternative sans-regex solution... Input (test.txt) Large toolbox (metal) for sale (hammer is required) serious inquiries only. All employees are required to attend. Meeting scheduled for Tuesday (Formal attire required) otherwise call (or email) us. Code $data = file('test.txt', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); foreach ($data as $line) { if ($p = parens_and_req($line)) { $line = str_replace($p, "<span style='color:red;'>$p</span>", $line ); } echo "<p>$line</p>"; } function parens_and_req($str) { $k = strlen($str); $p2 = 0; while (( $p1 = strpos($str, '(', $p2)) !== false ) { $p2 = strpos($str, ')', $p1); if ($p2 === false) { $p2 = $k-1; } $parens = substr($str, $p1, $p2-$p1+1); if (strpos($parens, 'required') !== false) { return $parens; } } return false; } Output
  5. There are errors in your HTML markup. Put the table inside the form, instead of the form inside the table. The cell containing your textarea has a <td> but no closing </td>
  6. Use DATE type columns for your dates, not varchar. Have your leaving dates either a valid date or NULL. SELECT eemp_id , fname , lname , AVG(timestampdiff(MONTH, joining_date, coalesce(leaving_date, curdate()))) as av_mths FROM employee_details ed JOIN employee e ON e.empid = ed.eemp_id GROUP BY eemp_id HAVING av_mths >= 36;
  7. My guess would be that you didn't find a matching record in candidate_paye in your second query. Don't run two queries, use a single query with a JOIN.
  8. Good. Your php.ini file is the correct place for them. It saves you having to put them in every script.
  9. You're right, but it won't break anything if it is there. For eaxample <?php $a = [1,2,3,4,5,]; echo '<pre>' . print_r($a, 1) . '</pre>'; ?> outputs Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
  10. foreach ($iterator as $filename => $fileInfo) { Where is the end of that foreach loop supposed to be?
  11. or go with an approach like this <?php // GET FUNCTION CALLS OUT OF THE WAY $thead = "<tr><th>".implode("</th><th>", array_keys($data[0]))."</th></th>\r\n"; $tdata = ''; foreach($data as $datum){ $tdata .= "<tr><td>".implode("</td><td>", $datum)."</td></tr>\r\n"; } // THEN $html = <<<HTML <table class="$class"> <thead> $thead </thead> <tbody> $tdata </tbody> </table> HTML; ?>
  12. And you don't see a problem with that? For example 1 2 3 4 5 6 7 8 9 10 Underline any number above that is both less than 5 and greater than 5
  13. I don't speak laravelese but is that query trying to find a date that is both greater than and less than $checkin_date?
  14. I have a room booking tutorial here, if it helps.
  15. Conspicuously absent is any attempt to use xpath as you were advised. Obviously spoonfeeding is required. Here's my version (slightly different from Requinix's, but not much) $xmlstr = <<<XML <kendisplay> <meta> <request>setData</request> <version>1</version> </meta> <data> <SText id="p1"> <text>test</text> </SText> <SText id="p2"> <text>test</text> </SText> <SText id="ken1"> <text>test</text> </SText> <SText id="wait"> <text>test</text> </SText> </data> </kendisplay> XML; $target_id = 'ken1'; $newtext = 'Updated'; $xml = simplexml_load_string($xmlstr); $path = sprintf("//SText[@id='%s']", htmlspecialchars($target_id) ); $ken = $xml->xpath($path); // find the SText $ken[0]->text = htmlspecialchars($newtext); // update its text $xml->asXML('test.xml'); // output updated xml file test.xml output ... <?xml version="1.0"?> <kendisplay> <meta> <request>setData</request> <version>1</version> </meta> <data> <SText id="p1"> <text>test</text> </SText> <SText id="p2"> <text>test</text> </SText> <SText id="ken1"> <text>Updated</text> </SText> <SText id="wait"> <text>test</text> </SText> </data> </kendisplay>
  16. https://www.php.net/manual/en/simplexmlelement.xpath.php
  17. To answer your question I would need to know what tables are in the database and the structures of those tables.
  18. If you want to cast the result of the method call to boolean, the "bool" needs to be on the right hand side of the assignment. Example ... $a = 5; $b = (bool) $a; var_dump($a); // int(5) var_dump($b); // bool(true)
  19. No idea what your csv data looks like, so going to use this (mytest.csv)... ,100,"Cancelled",, ,200,"Active",, ,300,"Pending",, then $fp = fopen('files/mytest.csv', 'r'); while ($row = fgetcsv($fp)) { $data[] = [ 'cost' => $row[1], 'status' => $row[2] ]; } fclose($fp); echo '<pre>' . print_r($data, 1) . '</pre>'; giving Array ( [0] => Array ( [cost] => 100 [status] => Cancelled ) [1] => Array ( [cost] => 200 [status] => Active ) [2] => Array ( [cost] => 300 [status] => Pending ) )
  20. I had quick look at TCPDF.php and it looks like it has a page rotation option.
  21. Put a "Post-It" note on your pack of #10 envelopes with the message "Other way up"
  22. Barand

    in_array()

    'false' is a string value, not a boolean false. From the PHP manual...
  23. Not to mention a complete disregard for the fact that id values should be unique.
  24. Don't use two queries (and two loops). Join to the users table and match on the criteria for accceptance (wallet and active) SELECT e.recipient , e.balance , e.posted_date FROM user_earnings e JOIN users u ON e.recipient = u.user_id AND wallet_address <> '' AND active AND balance > 100 JOIN ( SELECT recipient , MAX(posted_date) as posted_date FROM user_earnings GROUP BY recipient ) latest USING (recipient, posted_date) ;
  25. To make what more efficient. You still have told us what you are trying to do. What do the wallets have to do with the balance totals, for instance?
×
×
  • 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.