Jump to content

Barand

Moderators
  • Posts

    24,603
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. Are you now telling us that the php code that wasn't working was in a .html file and not in a .php file?
  2. $url = $row(['image_url']); ^ ^ remove ()s are for functions []s are for arrays It thinks you want to call a function called $res()
  3. @StevenOliver The final ";" before a "?>" is optional; the end of statement is implied.
  4. Yes, it's infuriating when it does what you tell it to do and not what you want it to do fwrite($contents, $number); ^ ^ number entered If you want N numbers when the user enter N, why are you always looping from 1 to 1000? Why two file opens?
  5. Try a combination approach, increasing the contrast to reduce the noise.
  6. 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)
  7. Your code is about 15 years out-of-date. As a minimum, replace "var" with "public" rename the function "publish(") to "__construct()"
  8. 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>"; } }
  9. That would depend on the code get the query results
  10. 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 | +--------+----------+---------+---------+---------+
  11. 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.
  12. 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
  13. 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']); }
  14. You can have only one else per if. You can have several elseif's though
  15. 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.
  16. 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>";
  17. 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 | +------+
  18. Try changing echo json_encode($data); to exit(json_encode($data));
  19. Have you checked what is being passed to and from the ajax call in your browsers developer tools?
  20. Put the variable value into a hidden field in the html. In the JS, get the value from the hidden field.
  21. foreach ($global_array as $k => $v) { foreach ($global_array as $k1 => $v1) { if ($k==$k1) continue; if (array_values(array_intersect($v, $v1)) == array_values($v1)) { unset($global_array[$k1]); } } }
  22. I don't see any subarrays in that array of yours that would be a candidate for removal - no duplicates edit: ignore me - I misunderstood the problem. "contained in" and not "equal"
  23. 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 ";
  24. 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>'; ?>
  25. 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.
×
×
  • 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.