Adsense
Popular Posts
- Code update from PHP 7.4 to PHP 8.1 - PhpSpreadsheet
- MySQL workbench -"Could not decrypt password cache"
- Code update from PHP 7.4 to PHP 8.1 - Worksheet/Iterator.php
- Rendering HTML tags inside textarea
- axios handle blob type data
- Unix Utils and wget in Windows
- increase mysql query speed
- Setup vi syntax for PHP
- Get WAMP running on EC2
- add comment to table columns in phpMyAdmin
Thursday, November 29, 2018
MySQl, current date add 2 months
MySQl, current date add 2 months
DATE_ADD(CURDATE(), INTERVAL (2) MONTH)
Example:
SELECT fhs.Term AS term,s.Stakeholder_id AS stakeholder_id FROM `fm_sita_historical` AS fhs
INNER JOIN
stakeholders AS s
ON s.Emplid = fhs.SFU_ID
UNION
SELECT semester AS term,stakeholder_id FROM `contract_si_ta_percourse`
WHERE cancelled='N'
AND (block='Y' OR gblock ='Y' OR cblock ='Y')
AND semester <(
SELECT `Term`
FROM terms_lut
WHERE DATE_ADD(CURDATE(), INTERVAL (2) MONTH) BETWEEN StartDate AND EndDate )
Wednesday, November 28, 2018
MySQL case when in order
Example of using CASE WHEN ... ELSE... END ) in ORDER BY in MySQL
ORDER BY
(CASE WHEN ranks.`EndDate` IS NULL OR ranks.`EndDate`='0000-00-00' OR TRIM(ranks.EndDate)='' THEN '9999-12-20'
ELSE
ranks.`EndDate` END) DESC,
Friday, November 23, 2018
Blank page/or undefined function mysql_pconnect() in CodeIgniter when upgrading from PHP5 to PHP 7
Run ttr_view1.php when upgrading from PHP5 to PHP 7, get blank page
<?php
if (!defined('BASEPATH')) die();
class Ttr_view1 extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('auth');
}
public function test(){
$data['styleSheets'] = array('ttr.css', 'shared.css');
$data['title'] = "Access Denied";
$this->load->view('access_denied', $data);
}
}
?>
Add
error_reporting(E_ALL);
ini_set('display_errors', '1');
at top, get error message
"Fatal error: Uncaught Error: Call to undefined function mysql_pconnect() in
/var/www/tracs/new6sp/system/database/drivers/mysql/mysql_driver.php:91 Stack trace: #0
/var/www/tracs/new6sp/system/database/DB_driver.php(115): CI_DB_mysql_driver->db_pconnect() #1
/var/www/tracs/new6sp/system/database/DB.php(148): CI_DB_driver->initialize() #2
/var/www/tracs/new6sp/system/core/Loader.php(346): DB(Array, NULL) #3
/var/www/tracs/new6sp/application/models/stakeholders.php(23): CI_Loader->database() #4"
In CodeIgniter application/config/database.php
/var/www/tracs/new6sp/application/config/database.php
line 56 change
$db['default']['dbdriver'] = 'mysql';
to
$db['default']['dbdriver'] = 'mysqli';
Left shift operation in PHP when upgrading from PHP5 to PHP 7
1<< -1 is OK for PHP 5, but fails for PHP 7.
Directly using 1<< -1 = -9223372036854775808
(Obtained from PHP Sandbox http://sandbox.onlinephpfunctions.com/)
/var/www/html/new6sp/application/controllers/ttr_view.php
line 781 change from
if($rcode < 33) {
$code = 1 << $rcode;
$r[$sid]['terms'][$term]['code'] |= $code;
}else{
$code = 1 << ($rcode-33);
$r[$sid]['terms'][$term]['code_upper'] |= $code;
}
to
if($rcode < 0) {
$code = -9223372036854775808;
$r[$sid]['terms'][$term]['code'] |= $code;
}
elseif($rcode < 33) {
$code = 1 << $rcode;
$r[$sid]['terms'][$term]['code'] |= $code;
}else{
$code = 1 << ($rcode-33);
$r[$sid]['terms'][$term]['code_upper'] |= $code;
}
Error message in PHP upgrade: Only variable references should be returned by reference
When I update PHP5.3 to PHP7, the following error message shows:
"A PHP Error was encountered
Severity: Notice
Message: Only variable references should be returned by reference
Filename: core/Common.php"
CodeIgniter system/core/Common.php
My code location:
/var/www/html/new6sp/system/core/Common.php
line 257 change
return $_config[0] =& $config;
to
$_config[0] =& $config;
return $_config[0];
JS/JQuery: paste the plain text only
When I copy the Word document to the text box,
in background a lot html codes and strange characters from Word
are saved.
Below is the JS/JQuery code to paste the plain text ( I have a text box with class comment):
function clickcomments($td){
$td.find('.comment').on('paste', function(event){
event.preventDefault();
var text = (event.originalEvent || event).clipboardData.getData('text/plain') || prompt('Paste something..');
window.document.execCommand('insertText', false, text);
$(this).html($(this).html().replace(/<div>/g, '<br>').replace(/<\/div>/g, '<br>'));
});
}
Wednesday, November 21, 2018
Replace a string in MySQL
MySQL Replace function to replace a string
REPLACE(str,old_string,new_string);
Example code in PHP:
$sql = "UPDATE courses_offered AS offered
INNER JOIN courses_lut
ON courses_lut.course_id = offered.course_id
LEFT JOIN contract_si_ta_percourse AS SITA
ON SITA.stakeholder_id = {$this->sanitizeInput($arr['stakeholder_id1'])}
AND SITA.Session0=offered.Session
AND SITA.courses_id = offered.course_id AND SITA.semester = offered.Term
AND CASE
WHEN LEFT(offered.Section ,2) ='OP'
THEN SITA.instr_section = offered.Section
WHEN TRIM(courses_lut.CourseSubject)='FASS' AND TRIM(courses_lut.CourseNumber)='101'
THEN SITA.instr_section = offered.Section
WHEN
left(offered.Section, 1) in ('A', 'N') and right(offered.Section, 1) = '0'
THEN
SITA.instr_section = CONCAT(LEFT(offered.Section ,3),'0')
ELSE SITA.instr_section = CONCAT(LEFT(offered.Section ,2),'00')
END
SET SITA.instr_section = REPLACE(SITA.instr_section, '$section1','$section2'),
SITA.assign_section = REPLACE(SITA.assign_section, '$section1','$section2')
WHERE offered.courses_offered_id = {$this->sanitizeInput($arr['courses_offered_id1'])}";
Get the dropdown list value and list in JQuery
I have a dropdown list class TaList in a column in a table.
To get the option value of dropdown list in JQuery:
row3.find('td.TaList select').val();
To get the selected text of dropdown list in JQuery:
stakeholder_name1 = row3.find('td.TaList :selected').text();
More codes:
$('div.ajax_list').find("#defaultTable").find('tr').each(function() {
if($(this).find('.swap_option').attr('checked') == 'checked') total += 1;
var row3= $(this);
if(total==1 && $(this).find('.swap_option').attr('checked') == 'checked'){
courses_offered_id1=row3.find("input.courses_offered_id").val();
stakeholder_id1 = row3.find('td.TaList select').val();
stakeholder_name1 = row3.find('td.TaList :selected').text();
section1 = row3.find('.TutSection').html();
assignedID1 = row3.find('.assignedID').val();
}
if(total==2 &&$(this).find('.swap_option').attr('checked') == 'checked'){
courses_offered_id2=row3.find("input.courses_offered_id").val();
stakeholder_id2 = row3.find('td.TaList select').val();
assignedID2 = row3.find('.assignedID').val();
stakeholder_name2 = row3.find('td.TaList :selected').text();
section2 = row3.find('.TutSection').html();
}
});
Subscribe to:
Posts (Atom)