-
Posts
24,613 -
Joined
-
Last visited
-
Days Won
834
Everything posted by Barand
-
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)); }));
-
This is when reading the manual comes in useful php.net/array_values php.net/array_unique php.net/sort
-
You could add these two lines foreach ($combinations as $k => &$a) sort($a); $combinations = array_values(array_unique($combinations, SORT_REGULAR));
-
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
-
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>
-
Searching and Calculating Minimum Years of experience
Barand replied to michelle1404's topic in MySQL Help
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; -
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.
-
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; ?>
-
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
-
I don't speak laravelese but is that query trying to find a date that is both greater than and less than $checkin_date?
-
I have a room booking tutorial here, if it helps.
-
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>
-
https://www.php.net/manual/en/simplexmlelement.xpath.php
-
How to create a search with multiple tables with php and mysqli
Barand replied to bis_codex's topic in PHP Coding Help
To answer your question I would need to know what tables are in the database and the structures of those tables. -
Using book Learn PHP 8 have an error that is wrong
Barand replied to Markus1954's topic in PHP Coding Help
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) -
PHP: Returning and naming specific fields from a CSV in an array
Barand replied to Sonva's topic in PHP Coding Help
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 ) ) -
I had quick look at TCPDF.php and it looks like it has a page rotation option.
-
Put a "Post-It" note on your pack of #10 envelopes with the message "Other way up"
-
'false' is a string value, not a boolean false. From the PHP manual...
- 1 reply
-
- 1
-
-
Not to mention a complete disregard for the fact that id values should be unique.
-
How do I combine values of same col inside a foreach loop?
Barand replied to imgrooot's topic in PHP Coding Help
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) ; -
How do I combine values of same col inside a foreach loop?
Barand replied to imgrooot's topic in PHP Coding Help
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?