Highlight mysql dynamically generated table based on user highlight and storing information permanently
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
|
show 4 more comments
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
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
|
show 4 more comments
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
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
javascript php jquery css ajax
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
|
show 4 more comments
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
|
show 4 more comments
1 Answer
1
active
oldest
votes
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 );
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 );
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
add a comment |
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 );
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
add a comment |
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 );
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 );
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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