Highlight mysql dynamically generated table based on user highlight and storing information permanently
NickName:Sarah Munir Ask DateTime:2018-11-19T22:41:59

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

Copyright Notice:Content Author:「Sarah Munir」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53376988/highlight-mysql-dynamically-generated-table-based-on-user-highlight-and-storing

More about “Highlight mysql dynamically generated table based on user highlight and storing information permanently” related questions

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

Show Detail

Highlight, then fade highlight, for list items dynamically added to a list

I have an unordered list on a page. When that page is refreshed through Ajax, new list items may come back that will be dynamically added to the unordered list. When the new list items get added, I

Show Detail

ExtJS - How to highlight dom element permanently?

I want to highlight a dom element permanently using Ext JS. Here is the common usage of Ext.dom.Element.highlight function: field.getEl().highlight('#fbac3d', { attr: "backgroundColor",

Show Detail

Highlight a row on table which is filled dynamically by assync resquest data

I have to update a table with rows which have data received by assync requests (JSON format). I'm doing this task very well (to create rows with the received data dynamically). Now I'm trying to se...

Show Detail

highlight dynamically generated text

I am creating a page to show pdf and I used pdf.js project of Mozilla to render pdf. pdf.js is making multiple dynamic divs of rendered text under canvas tag. I want to highlight some text of my p...

Show Detail

How to highlight search words in vim permanently?

I want to highlight the search keyword in Vim. Mainly I use vim to debug the logs. I always have to use :se hlsearch to highlight the search keyword. So, I want the solution that it should set co...

Show Detail

bootstrap table that dynamically adds rows to table and user then highlight and select a row

I need in bootstrap to have table starts an empty header and if the user selects certain button it will populate the table rows. Also at the same time the user should be able to highlight and selec...

Show Detail

How to highlight text permanently on android webview?

I am doing Epub reader and showing book inside android webview. At present i can highlight text using below javascript public static String Highlightscript = " &lt;script language=\"javascript\"...

Show Detail

How to set highlight duration permanently

I want to set the duration time of the Ext.get(el).highlight() function permanently. Is this possible without using cls? I have already tried to give infinity to the duration config. However I rece...

Show Detail

How to highlight selected row with jQuery?

I'm using jQuery 1.6.4 and I have an html table. I assign the table an id = "tbl" and then use a click event to dynamically find which row was clicked. In that row I want to highlight it so the u...

Show Detail