Highlight mysql dynamically generated table based on user highlight and storing information permanently












1















I have a table with a highlight option on each row. The table is generated dynamically from mysql data. Currently, when a user selects a color from a drop down menu, the color of the row changes. Each row has its own drop down. My question is, how can I store this css information in my database so the next time a user accesses the site the table is already highlighted? Here is the code I use to change the color of the table row when using the drop down



<script>
$(document).ready(function () {
$(document).on('click', 'tr', function () {
var color = ['none', 'green', 'yellow', 'red'];
$('select').change(function() {
$(this).parents('tr').css('background', color[$(':selected', this).index()]);
});
});
});
</script>


The table rows are generated dynamically using an ajax request. I know text can easily be made dynamic and updated but I am trying to find a way to modify a php or css sheet that can store the info. I am not sure how as the selected row here changes and each row has its own drop down.



Here is the code I use for generating each table row.



$(document).ready(function($)
{
function create_html_table (tbl_data)
{

//--->create data table > start
var tbl = '';
tbl +='<table>'

//--->create table header > start
tbl +='<thead>';
tbl +='<tr>';
tbl +='<th></th>';
tbl +='<th></th>';
tbl +='<th></th>';
tbl +='<th></th>';

tbl +='</tr>';
tbl +='</thead>';



tbl +='<tbody>';

$.each(tbl_data, function(index, val)
{
var row_id = val['row_id'];

tbl +='<tr row_id="'+row_id+'">';
tbl +='<td><select name="Select1"><option></option><option>Red</option><option>Yellow</option><option>Green</option></select></td>'
tbl +='<td ><div>'+val['']+'</div></td>';
tbl +='<td ><div>'+val['']+'</div></td>';
tbl +='<td ><div>'+val['']+'</div></td>';



tbl +='</tbody>';

tbl +='</table>';


//out put table data
$(document).find('.tbl_user_data').html(tbl);



}


var ajax_url = "<?php echo APPURL;?>/ajax.php" ;
var ajax_data = <?php echo json_encode($q1);?>;

//create table on page load
//create_html_table(ajax_data);

//--->create table via ajax call > start
$.getJSON(ajax_url,{call_type:'get'},function(data)
{
create_html_table(data);
});
//--->create table via ajax call > end









share|improve this question

























  • Missing information. But you can send ajax request and save it in a column for example in mysql, add column default color. From there you can check value during content creation in javascript. Include mysql or the database engine for more information

    – Edwin Dijas Chiwona
    Nov 19 '18 at 14:43













  • Is it possible to do that with the row as opposed to the column?

    – Sarah Munir
    Nov 19 '18 at 15:08











  • Its one in the same thing. The row in return have the specified column.

    – Edwin Dijas Chiwona
    Nov 19 '18 at 15:10











  • I'm using phpmyadmin. How do I set this color in the column after it is updated? I'm new to ajax requests so I'm just confused where to start.

    – Sarah Munir
    Nov 19 '18 at 15:29











  • Its a huge script. Will take me about an hour to complete. But i won't debug it this side. Will need help on that.

    – Edwin Dijas Chiwona
    Nov 19 '18 at 15:40
















1















I have a table with a highlight option on each row. The table is generated dynamically from mysql data. Currently, when a user selects a color from a drop down menu, the color of the row changes. Each row has its own drop down. My question is, how can I store this css information in my database so the next time a user accesses the site the table is already highlighted? Here is the code I use to change the color of the table row when using the drop down



<script>
$(document).ready(function () {
$(document).on('click', 'tr', function () {
var color = ['none', 'green', 'yellow', 'red'];
$('select').change(function() {
$(this).parents('tr').css('background', color[$(':selected', this).index()]);
});
});
});
</script>


The table rows are generated dynamically using an ajax request. I know text can easily be made dynamic and updated but I am trying to find a way to modify a php or css sheet that can store the info. I am not sure how as the selected row here changes and each row has its own drop down.



Here is the code I use for generating each table row.



$(document).ready(function($)
{
function create_html_table (tbl_data)
{

//--->create data table > start
var tbl = '';
tbl +='<table>'

//--->create table header > start
tbl +='<thead>';
tbl +='<tr>';
tbl +='<th></th>';
tbl +='<th></th>';
tbl +='<th></th>';
tbl +='<th></th>';

tbl +='</tr>';
tbl +='</thead>';



tbl +='<tbody>';

$.each(tbl_data, function(index, val)
{
var row_id = val['row_id'];

tbl +='<tr row_id="'+row_id+'">';
tbl +='<td><select name="Select1"><option></option><option>Red</option><option>Yellow</option><option>Green</option></select></td>'
tbl +='<td ><div>'+val['']+'</div></td>';
tbl +='<td ><div>'+val['']+'</div></td>';
tbl +='<td ><div>'+val['']+'</div></td>';



tbl +='</tbody>';

tbl +='</table>';


//out put table data
$(document).find('.tbl_user_data').html(tbl);



}


var ajax_url = "<?php echo APPURL;?>/ajax.php" ;
var ajax_data = <?php echo json_encode($q1);?>;

//create table on page load
//create_html_table(ajax_data);

//--->create table via ajax call > start
$.getJSON(ajax_url,{call_type:'get'},function(data)
{
create_html_table(data);
});
//--->create table via ajax call > end









share|improve this question

























  • Missing information. But you can send ajax request and save it in a column for example in mysql, add column default color. From there you can check value during content creation in javascript. Include mysql or the database engine for more information

    – Edwin Dijas Chiwona
    Nov 19 '18 at 14:43













  • Is it possible to do that with the row as opposed to the column?

    – Sarah Munir
    Nov 19 '18 at 15:08











  • Its one in the same thing. The row in return have the specified column.

    – Edwin Dijas Chiwona
    Nov 19 '18 at 15:10











  • I'm using phpmyadmin. How do I set this color in the column after it is updated? I'm new to ajax requests so I'm just confused where to start.

    – Sarah Munir
    Nov 19 '18 at 15:29











  • Its a huge script. Will take me about an hour to complete. But i won't debug it this side. Will need help on that.

    – Edwin Dijas Chiwona
    Nov 19 '18 at 15:40














1












1








1








I have a table with a highlight option on each row. The table is generated dynamically from mysql data. Currently, when a user selects a color from a drop down menu, the color of the row changes. Each row has its own drop down. My question is, how can I store this css information in my database so the next time a user accesses the site the table is already highlighted? Here is the code I use to change the color of the table row when using the drop down



<script>
$(document).ready(function () {
$(document).on('click', 'tr', function () {
var color = ['none', 'green', 'yellow', 'red'];
$('select').change(function() {
$(this).parents('tr').css('background', color[$(':selected', this).index()]);
});
});
});
</script>


The table rows are generated dynamically using an ajax request. I know text can easily be made dynamic and updated but I am trying to find a way to modify a php or css sheet that can store the info. I am not sure how as the selected row here changes and each row has its own drop down.



Here is the code I use for generating each table row.



$(document).ready(function($)
{
function create_html_table (tbl_data)
{

//--->create data table > start
var tbl = '';
tbl +='<table>'

//--->create table header > start
tbl +='<thead>';
tbl +='<tr>';
tbl +='<th></th>';
tbl +='<th></th>';
tbl +='<th></th>';
tbl +='<th></th>';

tbl +='</tr>';
tbl +='</thead>';



tbl +='<tbody>';

$.each(tbl_data, function(index, val)
{
var row_id = val['row_id'];

tbl +='<tr row_id="'+row_id+'">';
tbl +='<td><select name="Select1"><option></option><option>Red</option><option>Yellow</option><option>Green</option></select></td>'
tbl +='<td ><div>'+val['']+'</div></td>';
tbl +='<td ><div>'+val['']+'</div></td>';
tbl +='<td ><div>'+val['']+'</div></td>';



tbl +='</tbody>';

tbl +='</table>';


//out put table data
$(document).find('.tbl_user_data').html(tbl);



}


var ajax_url = "<?php echo APPURL;?>/ajax.php" ;
var ajax_data = <?php echo json_encode($q1);?>;

//create table on page load
//create_html_table(ajax_data);

//--->create table via ajax call > start
$.getJSON(ajax_url,{call_type:'get'},function(data)
{
create_html_table(data);
});
//--->create table via ajax call > end









share|improve this question
















I have a table with a highlight option on each row. The table is generated dynamically from mysql data. Currently, when a user selects a color from a drop down menu, the color of the row changes. Each row has its own drop down. My question is, how can I store this css information in my database so the next time a user accesses the site the table is already highlighted? Here is the code I use to change the color of the table row when using the drop down



<script>
$(document).ready(function () {
$(document).on('click', 'tr', function () {
var color = ['none', 'green', 'yellow', 'red'];
$('select').change(function() {
$(this).parents('tr').css('background', color[$(':selected', this).index()]);
});
});
});
</script>


The table rows are generated dynamically using an ajax request. I know text can easily be made dynamic and updated but I am trying to find a way to modify a php or css sheet that can store the info. I am not sure how as the selected row here changes and each row has its own drop down.



Here is the code I use for generating each table row.



$(document).ready(function($)
{
function create_html_table (tbl_data)
{

//--->create data table > start
var tbl = '';
tbl +='<table>'

//--->create table header > start
tbl +='<thead>';
tbl +='<tr>';
tbl +='<th></th>';
tbl +='<th></th>';
tbl +='<th></th>';
tbl +='<th></th>';

tbl +='</tr>';
tbl +='</thead>';



tbl +='<tbody>';

$.each(tbl_data, function(index, val)
{
var row_id = val['row_id'];

tbl +='<tr row_id="'+row_id+'">';
tbl +='<td><select name="Select1"><option></option><option>Red</option><option>Yellow</option><option>Green</option></select></td>'
tbl +='<td ><div>'+val['']+'</div></td>';
tbl +='<td ><div>'+val['']+'</div></td>';
tbl +='<td ><div>'+val['']+'</div></td>';



tbl +='</tbody>';

tbl +='</table>';


//out put table data
$(document).find('.tbl_user_data').html(tbl);



}


var ajax_url = "<?php echo APPURL;?>/ajax.php" ;
var ajax_data = <?php echo json_encode($q1);?>;

//create table on page load
//create_html_table(ajax_data);

//--->create table via ajax call > start
$.getJSON(ajax_url,{call_type:'get'},function(data)
{
create_html_table(data);
});
//--->create table via ajax call > end






javascript php jquery css ajax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 16:05









Oleg Nurutdinov

356213




356213










asked Nov 19 '18 at 14:41









Sarah MunirSarah Munir

113




113













  • Missing information. But you can send ajax request and save it in a column for example in mysql, add column default color. From there you can check value during content creation in javascript. Include mysql or the database engine for more information

    – Edwin Dijas Chiwona
    Nov 19 '18 at 14:43













  • Is it possible to do that with the row as opposed to the column?

    – Sarah Munir
    Nov 19 '18 at 15:08











  • Its one in the same thing. The row in return have the specified column.

    – Edwin Dijas Chiwona
    Nov 19 '18 at 15:10











  • I'm using phpmyadmin. How do I set this color in the column after it is updated? I'm new to ajax requests so I'm just confused where to start.

    – Sarah Munir
    Nov 19 '18 at 15:29











  • Its a huge script. Will take me about an hour to complete. But i won't debug it this side. Will need help on that.

    – Edwin Dijas Chiwona
    Nov 19 '18 at 15:40



















  • Missing information. But you can send ajax request and save it in a column for example in mysql, add column default color. From there you can check value during content creation in javascript. Include mysql or the database engine for more information

    – Edwin Dijas Chiwona
    Nov 19 '18 at 14:43













  • Is it possible to do that with the row as opposed to the column?

    – Sarah Munir
    Nov 19 '18 at 15:08











  • Its one in the same thing. The row in return have the specified column.

    – Edwin Dijas Chiwona
    Nov 19 '18 at 15:10











  • I'm using phpmyadmin. How do I set this color in the column after it is updated? I'm new to ajax requests so I'm just confused where to start.

    – Sarah Munir
    Nov 19 '18 at 15:29











  • Its a huge script. Will take me about an hour to complete. But i won't debug it this side. Will need help on that.

    – Edwin Dijas Chiwona
    Nov 19 '18 at 15:40

















Missing information. But you can send ajax request and save it in a column for example in mysql, add column default color. From there you can check value during content creation in javascript. Include mysql or the database engine for more information

– Edwin Dijas Chiwona
Nov 19 '18 at 14:43







Missing information. But you can send ajax request and save it in a column for example in mysql, add column default color. From there you can check value during content creation in javascript. Include mysql or the database engine for more information

– Edwin Dijas Chiwona
Nov 19 '18 at 14:43















Is it possible to do that with the row as opposed to the column?

– Sarah Munir
Nov 19 '18 at 15:08





Is it possible to do that with the row as opposed to the column?

– Sarah Munir
Nov 19 '18 at 15:08













Its one in the same thing. The row in return have the specified column.

– Edwin Dijas Chiwona
Nov 19 '18 at 15:10





Its one in the same thing. The row in return have the specified column.

– Edwin Dijas Chiwona
Nov 19 '18 at 15:10













I'm using phpmyadmin. How do I set this color in the column after it is updated? I'm new to ajax requests so I'm just confused where to start.

– Sarah Munir
Nov 19 '18 at 15:29





I'm using phpmyadmin. How do I set this color in the column after it is updated? I'm new to ajax requests so I'm just confused where to start.

– Sarah Munir
Nov 19 '18 at 15:29













Its a huge script. Will take me about an hour to complete. But i won't debug it this side. Will need help on that.

– Edwin Dijas Chiwona
Nov 19 '18 at 15:40





Its a huge script. Will take me about an hour to complete. But i won't debug it this side. Will need help on that.

– Edwin Dijas Chiwona
Nov 19 '18 at 15:40












1 Answer
1






active

oldest

votes


















0














JUST to get you started. Code may contain errors.
PART 1 SQL ADD NEW COLUMN



//SQL CREATE A COLUMN DEFAULT COLOR
//REPLACE MYTABLE with your table name
//REPLACE DBNAME with your databasename
//REPALCE default_color with your favourite column name
//YOU can also use uuid on your rows as unique key
//EXECUTE THIS SQL

ALTER TABLE `mytable` ADD COLUMN `default_color` VARCHAR(65) NULL DEFAULT NULL;


Part 2: JAVASCRIPT ANONYMOUS FUNCTION



var dy_tb_cr;

(function(){

'use strict';
var DYNAMIC_TABLE = function(){
dy_tb_cr = this;
};


DYNAMIC_TABLE.prototype.change = function( row_id, color ){
var data = 'color='+encodeURIComponent(color);
data += '&row_id=' encodeURIComponent(row_id);

this.xhr(data);
};

DYNAMIC_TABLE.prototype.xhr = function(data){
var url = 'update_row_color.php';
var xhr = new XMLHTTPRequest();
xhr.open( 'POST', url, true );
xhr.setRequestHeader( 'content-type', 'application/www-formdata-urlencoded' );
xhr.send();

};

new DYNAMIC_TABLE;

}());


//JS Usage Example
dy_tb_cr.change( 12, 'yellow' );


Part 3: PHP



//change_color.php
//Will

// get from post form



$row = filter_input( INPUT_POST, 'row_id' );
$color = filter_input( INPUT_POST, 'color' );

//PHP PART, HAS TO BE AN FILE
//SQL
//USING PDO ( MY FAVOURITE )
//YOU CAN USE YOUR FAVOURITE METHOD TO CHANGE
// UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id
$dsn = 'Mysql:host=127.0.0.1; port=3306; dbname = MYTABLE';

$sql = 'UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id';
$values = array( ':color' => $color, ':iid' => $row );
$pdo = new PDO( $dsn, $usr, $name );
$statement = $pdo->prepare( $sql );
$statement->execute( $values );





share|improve this answer
























  • Thank you so much! I upvoted you but it's not going through for some reason.

    – Sarah Munir
    Nov 20 '18 at 20:17











  • Its not a complete answer. Didn't text the code. Can you specify where you found the error.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:22











  • I have a few missing variables. I can only imagine how the table looks like but i don't know the exact structure. To debug this since its long, we need to start from the first sql statement all the way to php.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:25











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376988%2fhighlight-mysql-dynamically-generated-table-based-on-user-highlight-and-storing%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














JUST to get you started. Code may contain errors.
PART 1 SQL ADD NEW COLUMN



//SQL CREATE A COLUMN DEFAULT COLOR
//REPLACE MYTABLE with your table name
//REPLACE DBNAME with your databasename
//REPALCE default_color with your favourite column name
//YOU can also use uuid on your rows as unique key
//EXECUTE THIS SQL

ALTER TABLE `mytable` ADD COLUMN `default_color` VARCHAR(65) NULL DEFAULT NULL;


Part 2: JAVASCRIPT ANONYMOUS FUNCTION



var dy_tb_cr;

(function(){

'use strict';
var DYNAMIC_TABLE = function(){
dy_tb_cr = this;
};


DYNAMIC_TABLE.prototype.change = function( row_id, color ){
var data = 'color='+encodeURIComponent(color);
data += '&row_id=' encodeURIComponent(row_id);

this.xhr(data);
};

DYNAMIC_TABLE.prototype.xhr = function(data){
var url = 'update_row_color.php';
var xhr = new XMLHTTPRequest();
xhr.open( 'POST', url, true );
xhr.setRequestHeader( 'content-type', 'application/www-formdata-urlencoded' );
xhr.send();

};

new DYNAMIC_TABLE;

}());


//JS Usage Example
dy_tb_cr.change( 12, 'yellow' );


Part 3: PHP



//change_color.php
//Will

// get from post form



$row = filter_input( INPUT_POST, 'row_id' );
$color = filter_input( INPUT_POST, 'color' );

//PHP PART, HAS TO BE AN FILE
//SQL
//USING PDO ( MY FAVOURITE )
//YOU CAN USE YOUR FAVOURITE METHOD TO CHANGE
// UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id
$dsn = 'Mysql:host=127.0.0.1; port=3306; dbname = MYTABLE';

$sql = 'UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id';
$values = array( ':color' => $color, ':iid' => $row );
$pdo = new PDO( $dsn, $usr, $name );
$statement = $pdo->prepare( $sql );
$statement->execute( $values );





share|improve this answer
























  • Thank you so much! I upvoted you but it's not going through for some reason.

    – Sarah Munir
    Nov 20 '18 at 20:17











  • Its not a complete answer. Didn't text the code. Can you specify where you found the error.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:22











  • I have a few missing variables. I can only imagine how the table looks like but i don't know the exact structure. To debug this since its long, we need to start from the first sql statement all the way to php.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:25
















0














JUST to get you started. Code may contain errors.
PART 1 SQL ADD NEW COLUMN



//SQL CREATE A COLUMN DEFAULT COLOR
//REPLACE MYTABLE with your table name
//REPLACE DBNAME with your databasename
//REPALCE default_color with your favourite column name
//YOU can also use uuid on your rows as unique key
//EXECUTE THIS SQL

ALTER TABLE `mytable` ADD COLUMN `default_color` VARCHAR(65) NULL DEFAULT NULL;


Part 2: JAVASCRIPT ANONYMOUS FUNCTION



var dy_tb_cr;

(function(){

'use strict';
var DYNAMIC_TABLE = function(){
dy_tb_cr = this;
};


DYNAMIC_TABLE.prototype.change = function( row_id, color ){
var data = 'color='+encodeURIComponent(color);
data += '&row_id=' encodeURIComponent(row_id);

this.xhr(data);
};

DYNAMIC_TABLE.prototype.xhr = function(data){
var url = 'update_row_color.php';
var xhr = new XMLHTTPRequest();
xhr.open( 'POST', url, true );
xhr.setRequestHeader( 'content-type', 'application/www-formdata-urlencoded' );
xhr.send();

};

new DYNAMIC_TABLE;

}());


//JS Usage Example
dy_tb_cr.change( 12, 'yellow' );


Part 3: PHP



//change_color.php
//Will

// get from post form



$row = filter_input( INPUT_POST, 'row_id' );
$color = filter_input( INPUT_POST, 'color' );

//PHP PART, HAS TO BE AN FILE
//SQL
//USING PDO ( MY FAVOURITE )
//YOU CAN USE YOUR FAVOURITE METHOD TO CHANGE
// UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id
$dsn = 'Mysql:host=127.0.0.1; port=3306; dbname = MYTABLE';

$sql = 'UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id';
$values = array( ':color' => $color, ':iid' => $row );
$pdo = new PDO( $dsn, $usr, $name );
$statement = $pdo->prepare( $sql );
$statement->execute( $values );





share|improve this answer
























  • Thank you so much! I upvoted you but it's not going through for some reason.

    – Sarah Munir
    Nov 20 '18 at 20:17











  • Its not a complete answer. Didn't text the code. Can you specify where you found the error.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:22











  • I have a few missing variables. I can only imagine how the table looks like but i don't know the exact structure. To debug this since its long, we need to start from the first sql statement all the way to php.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:25














0












0








0







JUST to get you started. Code may contain errors.
PART 1 SQL ADD NEW COLUMN



//SQL CREATE A COLUMN DEFAULT COLOR
//REPLACE MYTABLE with your table name
//REPLACE DBNAME with your databasename
//REPALCE default_color with your favourite column name
//YOU can also use uuid on your rows as unique key
//EXECUTE THIS SQL

ALTER TABLE `mytable` ADD COLUMN `default_color` VARCHAR(65) NULL DEFAULT NULL;


Part 2: JAVASCRIPT ANONYMOUS FUNCTION



var dy_tb_cr;

(function(){

'use strict';
var DYNAMIC_TABLE = function(){
dy_tb_cr = this;
};


DYNAMIC_TABLE.prototype.change = function( row_id, color ){
var data = 'color='+encodeURIComponent(color);
data += '&row_id=' encodeURIComponent(row_id);

this.xhr(data);
};

DYNAMIC_TABLE.prototype.xhr = function(data){
var url = 'update_row_color.php';
var xhr = new XMLHTTPRequest();
xhr.open( 'POST', url, true );
xhr.setRequestHeader( 'content-type', 'application/www-formdata-urlencoded' );
xhr.send();

};

new DYNAMIC_TABLE;

}());


//JS Usage Example
dy_tb_cr.change( 12, 'yellow' );


Part 3: PHP



//change_color.php
//Will

// get from post form



$row = filter_input( INPUT_POST, 'row_id' );
$color = filter_input( INPUT_POST, 'color' );

//PHP PART, HAS TO BE AN FILE
//SQL
//USING PDO ( MY FAVOURITE )
//YOU CAN USE YOUR FAVOURITE METHOD TO CHANGE
// UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id
$dsn = 'Mysql:host=127.0.0.1; port=3306; dbname = MYTABLE';

$sql = 'UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id';
$values = array( ':color' => $color, ':iid' => $row );
$pdo = new PDO( $dsn, $usr, $name );
$statement = $pdo->prepare( $sql );
$statement->execute( $values );





share|improve this answer













JUST to get you started. Code may contain errors.
PART 1 SQL ADD NEW COLUMN



//SQL CREATE A COLUMN DEFAULT COLOR
//REPLACE MYTABLE with your table name
//REPLACE DBNAME with your databasename
//REPALCE default_color with your favourite column name
//YOU can also use uuid on your rows as unique key
//EXECUTE THIS SQL

ALTER TABLE `mytable` ADD COLUMN `default_color` VARCHAR(65) NULL DEFAULT NULL;


Part 2: JAVASCRIPT ANONYMOUS FUNCTION



var dy_tb_cr;

(function(){

'use strict';
var DYNAMIC_TABLE = function(){
dy_tb_cr = this;
};


DYNAMIC_TABLE.prototype.change = function( row_id, color ){
var data = 'color='+encodeURIComponent(color);
data += '&row_id=' encodeURIComponent(row_id);

this.xhr(data);
};

DYNAMIC_TABLE.prototype.xhr = function(data){
var url = 'update_row_color.php';
var xhr = new XMLHTTPRequest();
xhr.open( 'POST', url, true );
xhr.setRequestHeader( 'content-type', 'application/www-formdata-urlencoded' );
xhr.send();

};

new DYNAMIC_TABLE;

}());


//JS Usage Example
dy_tb_cr.change( 12, 'yellow' );


Part 3: PHP



//change_color.php
//Will

// get from post form



$row = filter_input( INPUT_POST, 'row_id' );
$color = filter_input( INPUT_POST, 'color' );

//PHP PART, HAS TO BE AN FILE
//SQL
//USING PDO ( MY FAVOURITE )
//YOU CAN USE YOUR FAVOURITE METHOD TO CHANGE
// UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id
$dsn = 'Mysql:host=127.0.0.1; port=3306; dbname = MYTABLE';

$sql = 'UPDATE `MYTABLE` SET `default_color` = :color WHERE `id` = :id';
$values = array( ':color' => $color, ':iid' => $row );
$pdo = new PDO( $dsn, $usr, $name );
$statement = $pdo->prepare( $sql );
$statement->execute( $values );






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 17:01









Edwin Dijas ChiwonaEdwin Dijas Chiwona

35118




35118













  • Thank you so much! I upvoted you but it's not going through for some reason.

    – Sarah Munir
    Nov 20 '18 at 20:17











  • Its not a complete answer. Didn't text the code. Can you specify where you found the error.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:22











  • I have a few missing variables. I can only imagine how the table looks like but i don't know the exact structure. To debug this since its long, we need to start from the first sql statement all the way to php.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:25



















  • Thank you so much! I upvoted you but it's not going through for some reason.

    – Sarah Munir
    Nov 20 '18 at 20:17











  • Its not a complete answer. Didn't text the code. Can you specify where you found the error.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:22











  • I have a few missing variables. I can only imagine how the table looks like but i don't know the exact structure. To debug this since its long, we need to start from the first sql statement all the way to php.

    – Edwin Dijas Chiwona
    Nov 20 '18 at 20:25

















Thank you so much! I upvoted you but it's not going through for some reason.

– Sarah Munir
Nov 20 '18 at 20:17





Thank you so much! I upvoted you but it's not going through for some reason.

– Sarah Munir
Nov 20 '18 at 20:17













Its not a complete answer. Didn't text the code. Can you specify where you found the error.

– Edwin Dijas Chiwona
Nov 20 '18 at 20:22





Its not a complete answer. Didn't text the code. Can you specify where you found the error.

– Edwin Dijas Chiwona
Nov 20 '18 at 20:22













I have a few missing variables. I can only imagine how the table looks like but i don't know the exact structure. To debug this since its long, we need to start from the first sql statement all the way to php.

– Edwin Dijas Chiwona
Nov 20 '18 at 20:25





I have a few missing variables. I can only imagine how the table looks like but i don't know the exact structure. To debug this since its long, we need to start from the first sql statement all the way to php.

– Edwin Dijas Chiwona
Nov 20 '18 at 20:25


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376988%2fhighlight-mysql-dynamically-generated-table-based-on-user-highlight-and-storing%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?