-
Posts
24,573 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
Converting grayscale image to pure black and white
Barand replied to DianaSimona's topic in PHP Coding Help
Have you tried $im = imagecreatefromjpeg('../images/celule.jpg'); imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_CONTRAST, -1000); header("Content-type: image/jpeg"); imagejpeg($im); imagedestroy($im); Emulating you matlab example $im = imagecreatefromjpeg('../images/celule.jpg'); imagefilter($im, IMG_FILTER_GRAYSCALE); $white = imagecolorallocate($im, 255,255,255); $black = imagecolorallocate($im, 0,0,0); $w = imagesx($im); $h = imagesy($im); for ($x=0; $x<$w; $x++) { for ($y=0; $y<$h; $y++) { $c = imagecolorat($im, $x, $y); if ($c & 0xFF > 190) // blue component imagesetpixel($im, $x, $y, $white); else imagesetpixel($im, $x, $y, $black); } } header("Content-type: image/jpeg"); imagejpeg($im); imagedestroy($im); Gives an effect like this (top-left corner of image) -
Your code is about 15 years out-of-date. As a minimum, replace "var" with "public" rename the function "publish(") to "__construct()"
-
You need to follow the chain of keys to the required value echo $contacts[1][1]['isPublished']; or foreach ($contacts[1][1] as $key => $value) { if (!is_array($value) { echo "$key : $value <br>"; } }
-
That would depend on the code get the query results
-
Alternatively, define your monetary amount columns as decimal(). This gives fixed number of decimal places. Here's an example DATA CREATE TABLE `income` ( CREATE TABLE `expense` ( `income_id` int(11) NOT NULL AUTO_INCREMENT, `expense_id` int(11) NOT NULL AUTO_INCREMENT, `userid` int(11) DEFAULT NULL, `userid` int(11) DEFAULT NULL, `pay_date` date DEFAULT NULL, `expend_date` date DEFAULT NULL, `amount` decimal(10,2) DEFAULT NULL, `expamount` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`income_id`), PRIMARY KEY (`expense_id`), KEY `idx_income_userid` (`userid`) KEY `idx_expense_userid` (`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8; income expense +-----------+--------+------------+---------+ +------------+--------+-------------+-----------+ | income_id | userid | pay_date | amount | | expense_id | userid | expend_date | expamount | +-----------+--------+------------+---------+ +------------+--------+-------------+-----------+ | 1 | 1 | 2020-01-01 | 2500.00 | | 1 | 1 | 2020-01-15 | 800.00 | | 2 | 1 | 2020-02-01 | 2650.00 | | 2 | 1 | 2020-01-25 | 250.00 | | 3 | 1 | 2020-03-01 | 2400.00 | | 3 | 2 | 2020-01-21 | 1500.00 | | 4 | 2 | 2020-01-01 | 3000.00 | | 4 | 2 | 2020-02-10 | 500.00 | | 5 | 2 | 2020-02-01 | 3100.00 | | 5 | 2 | 2020-03-15 | 1800.00 | | 6 | 2 | 2020-03-01 | 2800.00 | | 6 | 2 | 2020-03-20 | 1600.00 | +-----------+--------+------------+---------+ +------------+--------+-------------+-----------+ QUERY SELECT i.userid , mname , income , expense , income - expense as diff FROM ( SELECT userid , EXTRACT(YEAR_MONTH from pay_date) as month , MONTHNAME(pay_date) as mname , SUM(amount) as income FROM income GROUP BY userid, month ) i LEFT JOIN ( SELECT userid , EXTRACT(YEAR_MONTH from expend_date) as month , SUM(expamount) as expense FROM expense GROUP BY userid, month ) e USING (userid, month); +--------+----------+---------+---------+---------+ | userid | mname | income | expense | diff | +--------+----------+---------+---------+---------+ | 1 | January | 2500.00 | 1050.00 | 1450.00 | | 1 | February | 2650.00 | NULL | NULL | | 1 | March | 2400.00 | NULL | NULL | | 2 | January | 3000.00 | 1500.00 | 1500.00 | | 2 | February | 3100.00 | 500.00 | 2600.00 | | 2 | March | 2800.00 | 3400.00 | -600.00 | +--------+----------+---------+---------+---------+
-
You would use a query with a JOIN between the two tables to get the result SELECT FORMAT(i.amount - e.expamount, 2) as diff FROM incomeuser1 i JOIN expenseuser1 e ON i.whatever = e.whatever In your php code, apply a different css class if the diff value is -ve edit; When I see tables with a number suffix in their name I have doubts about the database design.
-
Take your pick SQL SELECT FORMAT(SUM(EXPAMOUNT), 2) as exptotal PHP $x = 5.5; echo sprintf("%0.2f", $x) . '<br>'; //--> 5.50 echo number_format($x, 2); //--> 5.50
-
Perhaps if (!file_exists($dest)) { //prevent file overwriting if (copy($url, $dest)) { $notify.= 'image saved: '. $row(['image_url']); $count++; } else { $notify.= 'ERROR saving image: '. $row(['image_url']); } } else { $notify.= 'image already exists: '. $row(['image_url']); }
-
You can have only one else per if. You can have several elseif's though
-
The problem is here (obvious when you look at the colour formatting of the posted code) $saveDir = "c:\wamp64\www\script\images\"; ^ "\"s are escape characters, so the final one escapes the ending ". You need to use \\ or / as path separators.
-
You don't need a separate query to get the column names. If your fetch() returns an associative array, the keys are the column names. $res = $db->query("SELECT * FROM lu_phase"); $row = $db->fetch(PDO::FETCH_ASSOC); echo "<table>"; echo "<tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>"; do { echo "<tr><td>" . join('</td><td>', $row) . '</td></th>'; } while ($row = $db->fetch(PDO::FETCH_ASSOC)); echo "</table>";
-
Use $diff->days. $dt1 = new DateTime('2020-05-01'); $diff = $dt1->diff(new DateTime())->d; //--> 14; $diff = $dt1->diff(new DateTime())->days; //--> 44; ->d gives the days as in "1 month 14 days" ->days gives the total days Using SQL: select datediff(curdate(), '2020-05-01') as days; +------+ | days | +------+ | 44 | +------+
-
Try changing echo json_encode($data); to exit(json_encode($data));
-
Have you checked what is being passed to and from the ajax call in your browsers developer tools?
-
Put the variable value into a hidden field in the html. In the JS, get the value from the hidden field.
-
Excerpts - Pull content into column, 100 characters max
Barand replied to jenniferabel's topic in PHP Coding Help
Why store the excerpt? You can just select the first 100 chars of the content when you want to display an excerpt. $sql = "SELECT b.id , b.title , c.name AS category , b.tags , content , LEFT(content, 100) as excerpt , photo , b.date AS pubDate , 'Jennifer' AS author FROM blogs AS b JOIN blog_categories c ON b.category=c.id WHERE posted = 'publish' ORDER BY DATE DESC LIMIT 2 "; -
help finding a matching word within a phrase of text. using a string.
Barand replied to x1705's topic in PHP Coding Help
If you are looking for words that are common to both $abs and $mT <?php $abs="one two three four words"; $mT = "testing for matching words"; $absArr = explode(' ', $abs); $mTArr = explode(' ', $mT); $common = array_intersect($absArr, $mTArr); // check result echo '<pre>', print_r($common, 1), '</pre>'; ?> -
You are setting the option values to $row['member'] but you don't select anything called "member" Why concatenate nothing at the end of the line? Why are you processing the posted data in the middle of your form output? Move it before the form. The $id in the form is doing nothing. Other problems you have already been told about and done nothing to fix them.
-
shopping cart not actually adding items to cart!! help!!
Barand replied to MsKazza's topic in PHP Coding Help
Let's narrow it down further ?schoolname={$school_page}?action=add -
Manipulate PHP Array for Google Product Feed (sizes to records)
Barand replied to John_A's topic in PHP Coding Help
therefore someone else in another forum had their time wasted too.- 11 replies
-
- 1
-
For the record, with PDO I get the types with query() and prepare() (although, as expected, dates are "string") $res = $db->query("select id , date , opposition , attendance from seasonstats limit 1"); $r = $res->fetch(); echo '<pre> query result <br>'; var_dump($r); $res = $db->prepare("select id , date , opposition , attendance from seasonstats limit 1"); $res->execute(); $r = $res->fetch(); echo '<pre> prepare result <br>'; var_dump($r); Results query result array(4) { ["id"]=> int(1) ["date"]=> string(10) "2010-08-07" ["opposition"]=> string(14) "Crystal Palace" ["attendance"]=> int(17486) } prepare result array(4) { ["id"]=> int(1) ["date"]=> string(10) "2010-08-07" ["opposition"]=> string(14) "Crystal Palace" ["attendance"]=> int(17486) }
-
Manipulate PHP Array for Google Product Feed (sizes to records)
Barand replied to John_A's topic in PHP Coding Help
It had occurred to me that an alternative approach to the problem might be on the cards, but without knowing what you were starting with there wasn't much anyone else could do. Hence the request for the input tables.- 11 replies
-
Manipulate PHP Array for Google Product Feed (sizes to records)
Barand replied to John_A's topic in PHP Coding Help
OK, if you're happy to continue coding your queries like that, I'll leave you to it.- 11 replies