使用Ajax从数据库隐藏/显示表列

I found a way to connect to my database and retrieve data but it's doesn't seem to be working when I try to hide/show my table column, I dont even know if it's possible with Ajax.

My Html:

<table class="footable" id="masterChart">
            <thead><tr><th data-class="expand" class="account">Account Number</th><th>Account Description</th><th>Level 01</th><th>Level 02</th><th>Level 03</th><th>Level 04</th><th>Tax</th><th>YTD - Current</th><th>YTD - Prior</th><th>MTD - Current</th><th>MTD - Prior</th></tr></thead>

            <?php $index = 0?>

            <?php while ($row = mysql_fetch_assoc($result)):?>

            <tr<?php echo $index++ % 2 ? ' class="even"' : ''?>>
                <td><?php echo $row['accountNumber']?></td>
                <td><?php echo $row['accountDescription']?></td>
                <td><?php echo $row['accountLevel1']?></td>
                <td><?php echo $row['accountLevel2']?></td>
                <td><?php echo $row['accountLevel3']?></td>
                <td><?php echo $row['accountLevel4']?></td>
                <td><?php echo $row['id']?></td>
                <td><?php echo $row['id']?></td>
                <td><?php echo $row['id']?></td>
                <td><?php echo $row['id']?></td>
                <td><?php echo $row['id']?></td>
            </tr>

            <?php endwhile?>

        </table>

My dbconn.php:

 <?php
  include_once('../classes/profile.class.php');

  $host = "localhost";
  $user = "root";
  $pass = "root";

  $databaseName = "accounting";
  $tableName = "login_table_display";

  //--------------------------------------------------------------------------
  // 1) Connect to mysql database
  //--------------------------------------------------------------------------

  $con = mysql_connect($host,$user,$pass);
  $dbs = mysql_select_db($databaseName, $con);

  //--------------------------------------------------------------------------
  // 2) Query database for data
  //--------------------------------------------------------------------------
  $user = $profile->getField('user_id');
  $result = mysql_query("SELECT * FROM '$tableName' WHERE user = '$user'");          //query
  $array = mysql_fetch_row($result);

  echo json_encode($array);
?>

I use the profile.class.php to get the user_id.

My ajax:

$(function () 
  {
    //-----------------------------------------------------------------------
    // 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/
    //-----------------------------------------------------------------------
    $.ajax({                                      
      url: 'dbconn.php',                  //the script to call to get data          
      data: "",                        //you can insert url argumnets here to pass to api.php
                                       //for example "id=5&parent=6"
      dataType: 'json',                //data format      
      success: function(data)          //on recieve of reply
      {
        var user = data[1];              //get id
        var table = data[2];            //get table name
        var column = data[3];           //get column
        var show = data[4];          //display or hide
        //--------------------------------------------------------------------
        // 3) Update html content
        //--------------------------------------------------------------------
        if (show == 0){
       $(table +'td:nth-child('+ column +'),th:nth-child('+ column +')').hide();
        //recommend reading up on jquery selectors they are awesome 
        // http://api.jquery.com/category/selectors/
        }
      } 
    });
}); 

I included the ajax.js file above to my file as:

<script src="ajax/ajax.js" type="text/javascript"></script>

If anyone can help or assist, I'd really appreciate it! If anyone has an alternative method of getting the database info and hiding the specific column, table for the user, i'd also appreciate it.

Ok so I got it right:

I added the profile.class.php wrong it was suppose to be ../classes/profile.class.php

Besides that, the jquery was wrong,

This:

$(table +'td:nth-child('+ column +'),th:nth-child('+ column +')').hide();

Needs to be this:

$('#'+ table +' td:nth-child(' + column + '), #' + table + ' th:nth-child(' + column + ')').hide();

And it's finding the show/hide value based on the users selection :)

Can you provide the full structure of your HTML? Do you start with any tables before calling the ajax request?

Besides that, try updating this:

if (show == 0){
  $(table +'td:nth-child('+ column +'),th:nth-child('+ column +')').hide();
}

With this:

if (show == 0){
  $(table +' td:nth-child(' + column + '),' + table + ' th:nth-child(' + column + ')').hide();
}