AndrisP 193 Posting Pro in Training

You are set 25 symbols (+9 white space) width for each column - maybe output window is not so large

AndrisP 193 Posting Pro in Training

Another version mutch more compact and easy to configure

    <script type="text/javascript">
    function donation(){
        this.range = {'min':1,'max':10};
        this.unit = {'hours':50, 'days':500, 'months':5000};
        this.init = function(){
            var sel = ['dn','sm','rs'];
            for(var k in sel){
                this[sel[k]] = document.getElementById(sel[k]);
            }
            this.dn.innerHTML="";
            for(var i=this.range.min; i<=this.range.max; i++){
                this.dn.innerHTML += '<option>'+(i)+'</option>';
            }
            this.sm.innerHTML="";
            for(var u in this.unit){
                this.sm.innerHTML += '<option>$'+(this.unit[u])+'</option>';
            }
            this.rs.innerHTML="";
            for(var u in this.unit){
                for(var i=this.range.min; i<=this.range.max; i++){
                    this.rs.innerHTML += '<option>'+(u=='days'?i*3:i)+' '+(u)+'</option>';
                }
            }
        }
        this.update = function(fromResult){
            if(fromResult){
                this.dn.selectedIndex = this.rs.selectedIndex % 10;
                this.sm.selectedIndex = Math.floor(this.rs.selectedIndex / 10);
            }
            else {
                this.rs.selectedIndex = this.dn.selectedIndex + (this.sm.selectedIndex*10);
            }
        }
    }
    var dnt = new donation;
    </script>
AndrisP 193 Posting Pro in Training

Not so beautiful but I found another solution - add --tee to make connection

mysql -u <username> -p -D <database> --tee ./install_$(date +"%Y-%m-%d_%H-%M").log

MySQL does not support dynamic filename in SQL script

AndrisP 193 Posting Pro in Training

@cereal - this do not workd inside SQL script file. I want to set command in script file

tee ./dinamic_file_name_here.log

or similar command

\T ./dinamic_file_name_here.log

but file name can not set dynamically to run script from command prompt e.g.

\T ./dinamic_file_name_here.log
\. ./make_tables.sql
\. ./install_routines.sql
\. ./install_triggers.sql
\. ./insert_start_setup.sql
AndrisP 193 Posting Pro in Training

That's not what I'm looking for - its for install script

rproffitt commented: On many MySQL installs, the logrotate is included. If not, pick a rabbit hole and choose what drink you want. (Yes, Alice in Wonderland references.) +12
AndrisP 193 Posting Pro in Training

Is the method in MySQL to set in SQL script dynamic log file name?
e.g in Oracle PL/SQL

set define on
column sdate new_value sdate
select to_char(sysdate,'YYYY.MM.DD_HH.MI') sdate from dual;
spool 'logs/install_&sdate..log';

e.g. in PG/SQL

\o ./logs/install_`date +"%Y-%m-%d_%H%M"`.log

but I cant find similar in MySQL

\T ??????
AndrisP 193 Posting Pro in Training

Would you think something like this?

<!DOCTYPE html>
<head>
    <script type="text/javascript">
    function donation(){
        this.dnts = [1,2,3,4,5,6,7,8,9,10];
        this.cost = [50,500,5000];
        this.unit = ['hours', 'days', 'months'];
        this.selected = [0,0];
        this.init = function(){
            this.dn = document.getElementById('dn');
            this.sm = document.getElementById('sm');
            this.rs = document.getElementById('rs');
            this.dn.innerHTML="";
            for(var i in this.dnts){
                this.dn.innerHTML += '<option>'+(this.dnts[i])+'</option>';
            }
            this.sm.innerHTML="";
            for(var i in this.cost){
                this.sm.innerHTML += '<option>$'+(this.cost[i])+'</option>';
            }
            this.rs.innerHTML="";
            for(var c in this.cost){
                for(var d in this.dnts){
                    this.rs.innerHTML += '<option>'+(Number(c)===1?this.dnts[d]*3:this.dnts[d])+' '+(this.unit[c])+'</option>';
                }
            }
        }
        this.update = function(fromResult){
            if(fromResult){
                this.dn.selectedIndex = this.rs.selectedIndex % 10;
                this.sm.selectedIndex = Math.floor(this.rs.selectedIndex / 10);
            }
            else {
                this.rs.selectedIndex = this.dn.selectedIndex + (this.sm.selectedIndex*10);
            }
        }
    }
    var dnt = new donation;
    </script>
</head>
<body onload="dnt.init();">
<div>
<span style="font-size:11px; font-family:arial;">
<select id="dn" onchange="dnt.update();">
</select> 
donation(s) of
<select id="sm" onchange="dnt.update();">
</select> 
= 
<select id="rs" onchange="dnt.update(1);">
</select> 
of gym time.</span>
</div>
</body>
</html>
Jon_7 commented: Wow, that is flawlessly what I meant! +1
AndrisP 193 Posting Pro in Training

Its a reserved keyword in MySQL. Read this https://dev.mysql.com/doc/refman/5.5/en/keywords.html

AndrisP 193 Posting Pro in Training

It should work similar. But column name date is not good - add prefix or use it inside backticks

AndrisP 193 Posting Pro in Training

Line 2 replace _init__ to __init__

AndrisP 193 Posting Pro in Training

Yes all good - unseparated output. Add new lines after each output.

cin >> x;
cout << x++ << "\n";
cout << ++x << "\n";
cout << x << "\n";
AndrisP 193 Posting Pro in Training

I think you need use left join and make all calculations in SQL. Something like this:

SELECT
    j.id
    ,j.journal_date
    ,j.balance
    ,COUNT(p.projection)
    -- calculate here
FROM
    journals j
LEFT JOIN
    projects p on j.user_id = p.user_id
WHERE
    j.user_id = '$user_id'
ORDER BY
    j.journal_date ASC
AndrisP 193 Posting Pro in Training

The windows analogue to MC is FAR but not fully functionality of MC - need additional plugin for compare files

AndrisP 193 Posting Pro in Training

Installable on any of Linux distributions. Do not need decompress before install it - use command line e.g. sudo dpkg -i path/to/archive.tar.xz
Usually I intall mc using direct comman line command sudo apt install mc to get and install latest version

AndrisP 193 Posting Pro in Training

That feature are available in MC - select files in to the left and right tab and then press and hold "Ctrl" and successively press "x", "d" or use Menu-tab: "Command"-"Compare files"

AndrisP 193 Posting Pro in Training

Midnight commander

AndrisP 193 Posting Pro in Training

ignore drop - I use it only in my test base before create tables

AndrisP 193 Posting Pro in Training

when you set header("Content-Type:text/plain"); or use it inside pre echo '<pre>'.$content.'</pre>;` then it should be work fine

diafol commented: Good advice +15
AndrisP 193 Posting Pro in Training

... and referenced column should be unique, in next example all working perfectly

drop table if exists `TABHDBHCHUYEN` cascade;
drop table if exists `TABHDBHCT` cascade;
drop table if exists `IDHDBHCT` cascade;

create table `IDHDBHCT` (
    `ID` int primary key not null auto_increment,
    `MAHDBH` int not null,
    constraint `UNIQUE_MAHDBH` unique key (`MAHDBH`)
);
create table `TABHDBHCHUYEN` (
    `ID` int primary key not null auto_increment,
    `NGAYCHUYEN` datetime,
    `MAHDBH` int not null,
    constraint `DBH_MAHDBH` foreign key (`MAHDBH`)
        references `IDHDBHCT`(`MAHDBH`) on delete cascade
);
create table `TABHDBHCT` (
    `ID` int primary key not null auto_increment,
    `MAHDBH` int not null,
    `IDHDBH` int not null,
    constraint `HCT_MAHDBH` foreign key (`MAHDBH`)
        references `IDHDBHCT`(`MAHDBH`) on delete cascade
);

insert into `IDHDBHCT`(`MAHDBH`)
    values (123),(234),(345);
insert into `TABHDBHCHUYEN`(`NGAYCHUYEN`,`MAHDBH`)
    values (now(),123)
    ,(date_add(now(), interval 1 day),234)
    ,(date_sub(now(), interval 1 day),345);
insert into `TABHDBHCT`(`IDHDBH`,`MAHDBH`)
    values (11,123),(22,234),(33,345);

check inserts

SELECT * FROM `IDHDBHCT`;
SELECT * FROM `TABHDBHCHUYEN`;
SELECT * FROM `TABHDBHCT`;

delete row 2 (affected all tables)

delete from `IDHDBHCT` where `ID` = 2;

check all tables

SELECT * FROM `IDHDBHCT`;
SELECT * FROM `TABHDBHCHUYEN`;
SELECT * FROM `TABHDBHCT`;
AndrisP 193 Posting Pro in Training

Make foreign key constraints with clause on delete cascade on the tables 2 and 3 referenced to table 1 and dont use join for deleting.

AndrisP 193 Posting Pro in Training
AndrisP 193 Posting Pro in Training

I suggest you use function filter_input()

$edit = filter_input(INPUT_GET,  'edit', FILTER_VALIDATE_INT);
$delete = filter_input(INPUT_GET,  'delete', FILTER_VALIDATE_INT);
$brand = filter_input(INPUT_POST,  'brand', FILTER_SANITIZE_STRING);
if($edit !== NULL){
    $sql = ....
}
if($delete !== NULL){
    $sql = ....
}
if(isset($_POST['add_submit']) && $brand !== NULL){
    $sql = ....
}

and bind variables after prepare SQL statement!

AndrisP 193 Posting Pro in Training

Why don't you use theloadXML function and then handle it through the DOM object? http://php.net/manual/en/domdocument.loadxml.php

AndrisP 193 Posting Pro in Training

Another way - format date in to the db, e.g.

$stmt = $conn->prepare("SELECT DATE_FORMAT(`your_date_column`, '%W %M %D') FROM tbl ORDER BY id DESC");

More MySQL date formating info here here

AndrisP 193 Posting Pro in Training

My comment will not answer to your question but:

Is the column uid with type VARCHAR? I think it should be integer. If its true then bind variable as PDO::PARAM_INT and I recommend use

$uid = filter_input(INPUT_POST, 'uid', FILTER_VALIDATE_INT);

instead of

    $uid = false;
    if(isset($_POST['uid'])){
        $uid = $_POST['uid'];
     }

function filter_input() set variable to NULL if not set or value not parsed as integer.

AndrisP 193 Posting Pro in Training
order by
    if(
        substr(`ord_column`, 1, 2)='A ',
        substr(`ord_column`, 3),
        if(
            substr(`ord_column`, 1, 4)='The ',
            substr(`ord_column`, 5),
            `ord_column`
            )
        )

or mutch readable (result will be same)

order by
    case
        when substr(`ord_column`, 1, 2)='A ' then substr(`ord_column`, 3)
        when substr(`ord_column`, 1, 4)='The ' then substr(`ord_column`, 5)
        else `ord_column`
    end
AndrisP 193 Posting Pro in Training

In to the line 5 you are trying to handle $row but it not defined in this step

function two_dim_array_to_html_table($arr, $header){
    $ret = "<table border='1'>\n";
    $ret .= "\t<tr>\n";
    foreach($arr[0] as $key => $val){ // use set of $key only but $val do not use
        $ret .= "\t\t<th>".$header[$key]."</th>\n";
        }
    $ret .= "\t</tr>\n";
    foreach($arr as $row){
        $ret .= "\t<tr>\n";
        foreach($row as $column){
            $ret .= "\t\t<td>".$column."</td>\n";
            }
        $ret .= "\t</tr>\n";
        }
    $ret .= "<table>\n";
    return $ret;
    }
AndrisP 193 Posting Pro in Training

On the call function

    $Body = "<html>\n"
        . "<head>\n"
        . "<style>\n"
        . file_get_contents('style.css')
        . "</style>\n"
        . "</head>\n"
        . "<body>\n" 
        . two_dim_array_to_html_table($result, $colcomments)
        . "</body>\n"
        . "</html>\n";

but inside function when you generate column headers need foreach first row of array to get similar set of indexes because array $colcomments may contain more key pairs

AndrisP 193 Posting Pro in Training

You forgot to pass second input parameter when you call function

AndrisP 193 Posting Pro in Training

You forgot to add the second input parameter to function. Table row tags <tr> open and close for column headers is missing. Lines 11. and 12. should be before line 5.

AndrisP 193 Posting Pro in Training

Replace function and pass array $colcomments as second argument. Then before foreach($arr as $row) implement column headers

AndrisP 193 Posting Pro in Training

Put style attributes directly in to the HTML elements instead of CSS stylesheet

AndrisP 193 Posting Pro in Training

Create it as function e.g.

function two_dim_array_to_html_table($arr){
    $ret = "<table border='1'>\n";
    foreach($arr as $row){
        $ret .= "\t<tr>\n";
        foreach($row as $column){
            $ret .= "\t\t<td>".$column."</td>\n";
            }
        $ret .= "\t</tr>\n";
        }
    $ret .= "<table>\n";
    return $ret;
    }

and call it instead of json_encode

$Body = "<html>\n"
    . "<head>\n"
    . "<style>\n"
    . file_get_contents('style.css')
    . "</style>\n"
    . "</head>\n"
    . "<body>\n" 
    . two_dim_array_to_html_table($result)
    . "</body>\n"
    . "</html>\n";
AndrisP 193 Posting Pro in Training

Create function for convert array to html table instead of json_encode

AndrisP 193 Posting Pro in Training

Because $result is array - do not concatenate as a string

AndrisP 193 Posting Pro in Training

Mark thread as solved

AndrisP 193 Posting Pro in Training

In fact checkboxes is redundant because rows with no changes will not updated - replace all "checkbox" to "hidden"

AndrisP 193 Posting Pro in Training

Easiest way to select all by default add attribute checked. Or replace type "checkbox" to "hidden" and remove labels if you dont want deselect.

AndrisP 193 Posting Pro in Training

About Undefined variable: declare variables $result and also $colcomments - before try { in my code example in to the line 86 - e.g. $result = NULL; $colcomments = NULL;
Column comments should be in MySQL table column comments. Modify existing columns via phpMyAdmin or MySQLworkbench e.g.

ALTER TABLE `crqtracker` CHANGE COLUMN `changeid` `changeid` INT NOT NULL COMMENT 'CID';
ALTER TABLE `crqtracker` CHANGE COLUMN `taskid` `taskid` INT NOT NULL COMMENT 'TID';
-- etc
AndrisP 193 Posting Pro in Training

Try this

<?php

define('DBhost', 'localhost');
define('DBname', 'trackerdb');
define('DBport', 3306);
define('DBuser', 'root');
define('DBpswd', '');

$message = array(
    'error' => array(),
    'warning' => array(),
    'info' => array()
);
$bgcol = array(
    'error' => '#FFDDDD',
    'warning' => '#FFFFDD',
    'info' => '#DDFFDD'
);

function check_date(&$message, $value, $per){
    if($value == "" || $value === NULL){
        if(isset($_POST[$per])){ // empty variable is set in form
            $message['warning'][] = "Date ".$per." is not set";
            } // else without message (form not submited)
        return NULL;
        }
    elseif(preg_match('/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/', $value)){
        return $value;
    }
    $message['error'][] = "Invalid date: ".$value;
    return NULL;
}

$date_args = array(
    'from' => array(
        'filter'    => FILTER_CALLBACK,
        'options'   => (function($value) use(&$message){
            return check_date($message, $value, "from");
        })
    ),
    'to' => array(
        'filter'    => FILTER_CALLBACK,
        'options'   => (function($value) use(&$message){
            return check_date($message, $value, "to");
        })
    )
);

$update_args = array(
    'id' => array(
        'filter' => FILTER_VALIDATE_INT,
        'flags' => FILTER_REQUIRE_ARRAY
    ),
    'changeid' => array(
        'filter' => FILTER_FLAG_NO_ENCODE_QUOTES,
        'flags' => FILTER_REQUIRE_ARRAY
    ),
    'taskid' => array(
        'filter' => FILTER_FLAG_NO_ENCODE_QUOTES,
        'flags' => FILTER_REQUIRE_ARRAY
    ),
    'summary' => array(
        'filter' => FILTER_FLAG_NO_ENCODE_QUOTES,
        'flags' => FILTER_REQUIRE_ARRAY
    ),
    'type' => array(
        'filter' => FILTER_FLAG_NO_ENCODE_QUOTES,
        'flags' => FILTER_REQUIRE_ARRAY
    ),
    'reviewed_approved_by' => array(
        'filter' => FILTER_FLAG_NO_ENCODE_QUOTES,
        'flags' => FILTER_REQUIRE_ARRAY
    ),
    'scheduled_start_date' => array(
        'filter' => FILTER_FLAG_NO_ENCODE_QUOTES,
        'flags' => FILTER_REQUIRE_ARRAY
    ),
    'implemented_by' => array(
        'filter' => FILTER_FLAG_NO_ENCODE_QUOTES,
        'flags' => FILTER_REQUIRE_ARRAY
    )
);

$update = filter_input_array(INPUT_POST, $update_args);
$date = filter_input_array(INPUT_POST, $date_args);

$dsn = 'mysql:dbname='.DBname.';host='.DBhost.';port='.DBport;
try {
    $conn = new PDO($dsn, DBuser, DBpswd);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    if(isset($update['id']) && is_array($update['id']) && !empty($update['id'])){
        $sql = "UPDATE `crqtracker`
            SET `changeid` = :bv_changeid
            ,`taskid` = :bv_taskid
            ,`summary` = :bv_summary
            ,`type` …
AndrisP 193 Posting Pro in Training

You are wrong - update will be skipped when it is not set but if you submit updates then need set updates in to the table before you again select data else you see old data in form.

AndrisP 193 Posting Pro in Training

Another way - create document object and manipulate any element and its attributes e.g.

<?php

$content = '<!DOCTYPE html>
<html>
<head>
    <title>PAGE TITLE</title>
</head>
<body>
    <p>This content has two images</p>
    <div>
        <img src="/images/img1.jpg" alt="Image 1" />
        <img src="/images/img2.jpg" alt="Image 2" />
    </div>
</body>
</html>';

$doc = new DOMDocument();
$doc->loadHTML($content);

// prepare document object ...

echo $doc->saveHTML();

?>
AndrisP 193 Posting Pro in Training
<?php
$content = 'This content has two images
<img src="/images/img1.jpg" alt="Image 1" />
<img src="/images/img2.jpg" alt="Image 2" />';

$content = preg_replace('/\<img src="([^\"]+)" alt="([^\"]+)" \/>/',
    '<a href="\\1" data-fancybox="image-popup" data-caption="\\2">
        <img src="\\1" alt="\\2" />
    </a>', $content);

header("Content-type:text/plain;charset=utf-8");
print_r($content);
?>
AndrisP 193 Posting Pro in Training

Update functions should be before line 28 to take update effects in your SELECT
All POST variables would be better with filter_input_array() function e.g.

$args = array(
    'id' => array(
        'filter'    => FILTER_VALIDATE_INT
    ),
    'changeid' => array(
        'filter'    => FILTER_FLAG_NO_ENCODE_QUOTES
    ),
    'taskid' => array(
        'filter'    => FILTER_FLAG_NO_ENCODE_QUOTES
    ),
    'summary' => array(
        'filter'    => FILTER_FLAG_NO_ENCODE_QUOTES
    ),
    'type' => array(
        'filter'    => FILTER_FLAG_NO_ENCODE_QUOTES
    ),
    'reviewed_approved_by' => array(
        'filter'    => FILTER_FLAG_NO_ENCODE_QUOTES
    ),
    'scheduled_start_date' => array(
        'filter'    => FILTER_FLAG_NO_ENCODE_QUOTES
    ),
    'implemented_by' => array(
        'filter'    => FILTER_FLAG_NO_ENCODE_QUOTES
    )
);

$post = filter_input_array(INPUT_POST, $args);

instead of lines 115..122

AndrisP 193 Posting Pro in Training

Your input tags is not not closed in to the lines 79..84
Lines 15..17 is duplicat of lines 11..13
I recommend use $date = filter_input(INPUT_POST, 'date'); and $date1 = filter_input(INPUT_POST, 'date1'); instead of $date = $_POST['date']; because it raise warning - undefined index if variables is not set. And then check if($date !== NULL && $date1 !== NULL){ ... } before SELECT (line 28)

AndrisP 193 Posting Pro in Training

If you want to update only column3 then do not need put in form other columns

<?php
echo '
<form action="crqretrieve_status.php" method="post">
    <table>';

foreach ($result as $row => $info) {
    echo '
<tr>
    <td align="center">
        '.$info['column1'].'
    </td>
    <td align="center">
        '.$info['column2'].'
    </td>
    <td align="center">
        <input type="text" name="id['.$info['id'].']" value="'.$info['column3'].'" />
    </td>
</tr>'; 
    }

echo '
    </table>
</form>';
?>

Update foreach

<?php
foreach($_POST['id'] as $key => $val)
{
    $id = filter_var($key, FILTER_VALIDATE_INT);
    $column3 = filter_var($val, FILTER_SANITIZE_STRING);

    // if everything is fine, update the record in the database
    if($id !== NULL && $column3 !== NULL)
    {
        if ($stmt = $mysqli->prepare("UPDATE sample_table SET column3 = ? WHERE id = ? "))
        {
            $stmt->bind_param("si", $column3, $id);
            $stmt->execute();
            $stmt->close();
        }
    }
}
?>
AndrisP 193 Posting Pro in Training

Where from do you get values for update? Its manual input or other?

AndrisP 193 Posting Pro in Training
select * from some_table where `last order date` < date_sub(now(), interval 3 month)
AndrisP 193 Posting Pro in Training

decrease max-width

AndrisP 193 Posting Pro in Training

Define in css float:left; sizes max-width and max-height
use it class instead of style="float:left;"