AndrisP 193 Posting Pro in Training

I think You need normalize DB-tables for first.

create table Pensyarah(
    IDPensyarah integer not null primary key auto_increment
  , IDUser varchar(50) not null
  , NamaPensyarah varchar(100) not null
  , Email varchar(50) not null
  , NoTel varchar(11) not null
);

create table Kursus(
    IDKursus integer not null primary key auto_increment
  , Semester integer not null
  , KodKursus varchar(50) not null
  , NamaKursus varchar(50) not null
);

create table PensyarahKursusRefs(
    PensyarahKursus integer not null primary key auto_increment
  , IDPensyarah integer not null
  , IDKursus integer not null
  , constraint IDPens_IDKurs_Sem_UQ unique key (Semester,IDPensyarah,IDKursus)
  , constraint Pensyarah_FK foreign key (IDPensyarah) references Pensyarah(IDPensyarah)
  , constraint Kursus_FK foreign key (IDKursus) references Kursus(IDKursus)
);

Then creat view for convenient select list of "Kursus" in one column
like in sample:

create or replace view PensyarahKursus as
select
    p.IDUser
  , p.NamaPensyarah
  , p.Email
  , p.NoTel
  , k.Semester
  , group_concat(k.KodKursus separator ', ') kursusList
from Pensyarah p
left join PensyarahKursusRefs pkr using(IDPensyarah)
left join Kursus k using(IDKursus)
group by
    p.IDUser
  , p.NamaPensyarah
  , p.Email
  , p.NoTel
  , k.Semester
;

You can create procedure for convenient reference inserting:

delimiter $$
create procedure set_Kursus_ref(
    in p_IDUser varchar(50)
  , in p_KodKursus varchar(50)
)
begin
  insert into PensyarahKursusRefs(IDPensyarah,IDKursus) values (
      (select p.IDPensyarah from Pensyarah p where p.IDUser = p_IDUser)
    , (select k.IDKursus from Kursus k where k.KodKursus = p_KodKursus)
  );
end; $$
delimiter ;

Then sample insert and select:

insert into Pensyarah(IDUser,NamaPensyarah,Email,NoTel)
  values ('sample_ID_user_1','sample_Nama_1','sample.1@sapmle.com','11111111111');
insert into Pensyarah(IDUser,NamaPensyarah,Email,NoTel)
  values ('sample_ID_user_2','sample_Nama_2','sample.2@sapmle.com','22222222222');
insert into Pensyarah(IDUser,NamaPensyarah,Email,NoTel)
  values ('sample_ID_user_3','sample_Nama_3','sample.3@sapmle.com','33333333333');

insert into Kursus(Semester,KodKursus,NamaKursus) values (1,'KK-1','KursusNama-1');
insert into Kursus(Semester,KodKursus,NamaKursus) values …
AndrisP 193 Posting Pro in Training

a small correction to my post

    $ip = filter_input(INPUT_SERVER,'REMOTE_ADDR',FILTER_VALIDATE_IP);
    $stmt->execute([$ip,$ip,$ip]);
AndrisP 193 Posting Pro in Training

You can insert all these values witout trigger e.g. use prepared statement:

insert into download (
    `ADDRESS`
    ,`ip_address`
    ,`vrefer`
)
select
    ?
    ,inet_aton(?)
    ,(select id from `ip_lookup` where inet_aton(?) between ip_lookup.start and ip_lookup.end limit 1)
;

and execute with array 3 times pass IP

$stmt->execute(['127.0.0.1','127.0.0.1','127.0.0.1']);

or pure SQL version:

set @ip='127.0.0.1';
insert into download (
    `ADDRESS`
    ,`ip_address`
    ,`vrefer`
)
select
    @ip
    ,inet_aton(@ip)
    ,(select id from `ip_lookup` where inet_aton(@ip) between ip_lookup.start and ip_lookup.end limit 1)
;
AndrisP 193 Posting Pro in Training

Don't need declare - select values direct to fields

DELIMITER //
CREATE TRIGGER download_ins  BEFORE INSERT ON download 
    FOR EACH ROW begin
    set new.ip_address = inet_aton(new.`ADDRESS`);
    set new.vrefer=(select id
            from `ip_lookup`
            where inet_aton(new.`ADDRESS`) between ip_lookup.start and ip_lookup.end
            limit 1
        );
END; //
DELIMITER ;
AndrisP 193 Posting Pro in Training

Get value from array by key $temp['IP_ADDRESS'] but use of between in your code is wrong - should be convert by INET_ATON

AndrisP 193 Posting Pro in Training

It's a very simple in single row:

string='India is a democracy'
print (' '.join([word for word in reversed(string.split(' '))]))
Aman_24 commented: thank u +0
AndrisP 193 Posting Pro in Training

Read tech spec abot your graphic card - max count of monitors, sum of max pixel-width and sum of max pixel-height

AndrisP 193 Posting Pro in Training

In nyour code if case in line 32 allways true because actually you check if exist array which defined inside self if case.
Get file extension e.g.

$ext = pathinfo($_FILES["images"]["name"], PATHINFO_EXTENSION);

and then check if in array e.g.

if(!in_array(strtolower($ext), $allowed)){
    die("Not a gif/jpeg/png");
}
AndrisP 193 Posting Pro in Training

Use send_long_datahttp://php.net/manual/en/mysqli-stmt.send-long-data.php for blob upload in to the DB and use prepared statement to prevent from SQL injection.

AndrisP 193 Posting Pro in Training

Add backslashes before apostrophes onclick="window.location.href='route(\'pemesanan\')';" if you have to pass string pemesanan or add plus onclick="window.location.href='route('+pemesanan+')';" if "pemesanan" is javascript (number or object) variable name
or put both if it string variable name onclick="window.location.href='route(\''+pemesanan+'\')';"

AndrisP 193 Posting Pro in Training

Sorry i was wrong about last 4 bits

AndrisP 193 Posting Pro in Training

Actually results is numbers divisible by 12. Another way to find - check last 4 bits. It should be 1100

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

Line 2 replace _init__ to __init__

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

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
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

Maybe browser show cached images. Try generate different file names to output image

rproffitt commented: Good point. Thing 1, Thing 2, etc. +12
AndrisP 193 Posting Pro in Training

line 13 should be print(self.question)
and similar mistake in the line 22

AndrisP 193 Posting Pro in Training

"Map network drive" if you are windows user, or open network folder and then save bookmark if you are linux user.

AndrisP 193 Posting Pro in Training

You can define function

delimiter $$
create function not_max_of_division(
     p_product varchar(30)
    ,p_division varchar(30)
) returns boolean
begin
    declare v_max int;
    declare v_not_max boolean;
    select
        max(t.`sales`) into v_max
    from
        `sample` t
    where
        t.`Division` = p_division;
    select
        t.`sales` <> v_max into v_not_max
    from
        `sample` t
    where
        t.`product` = p_product;
    return v_not_max;
end $$
delimiter ;

and then

select t.* from `sample` t
where not_max_of_division(t.`product`, t.`Division`)
order by
     t.`Division` asc
    ,t.`sales` desc;

(do not need set sql_mode)

AndrisP 193 Posting Pro in Training

In to the subquery you can select max(sales) group by Division then select * from SAMPLE where product not in (subquery) eg

select
    t.*
from
    `sample` t
where
    t.`product` not in (
        select
            s.`product` from (
            select
                 m.`product`
                ,max(m.`sales`)
            from
                `sample` m
            group by m.`Division`
        ) s
    )
order by
     t.`Division` asc
    ,t.`sales` desc;

if your MySQL version is 5.7 then before this query set sql_mode

set sql_mode=(select replace(lower(@@sql_mode),'only_full_group_by',''));
k_manimuthu commented: Thanks for your solution +5
AndrisP 193 Posting Pro in Training

@ deceptikon - Thank you for comment. I will follow on your recommendation.

AndrisP 193 Posting Pro in Training

... or use bitwise operator if(i&1) if true even else odd. Its faster because compare one bit only without mathematics

AndrisP 193 Posting Pro in Training

Your pattern checked only first character. Change to:
(!preg_match("/^[0-9a-zA-Z ]+$/", $name3))

Aeonix commented: Yea! +4
AndrisP 193 Posting Pro in Training

PHP arrays unlimited levels but ini file seems 2 levels only

AndrisP 193 Posting Pro in Training

Make multidimensional array eg

$categories = array(
    'cars' => array(
        'BMW' => array(
            'X1',
            'X3',
            'X5',
            'X6'
        ),
        'AUDI' => array(
            'A3',
            'A6'
        ),
        'MERCEDES'
    ),
    'moto' => array(
        'SUZUKI',
        'HONDA',
        'YAMAHA'
    ),
    'phones' => array(
        'SAMSUNG',
        'LG',
        'MOTOROLA'
    )
);
// etc

You can write data to ini file if it's much readable for you and build array with parse_ini_file() http://php.net/manual/en/function.parse-ini-file.php

Stefce commented: How much sub-arrays i can have ? +2
AndrisP 193 Posting Pro in Training

Make DB table for categories and another table for brends with foreigh keys constraints referenced to categories and another table for models with constraints referenced to brends

AndrisP 193 Posting Pro in Training

oh sorry its a copy-paste