2014-03-29 23 views
0

我能够将行拖放到表格中,但我在列中遇到困难。我的bellow JavaScript似乎并没有工作。任何帮助将不胜感激拖放列PHP,JS,该怎么做?

<?php 


if(!$link = mysql_connect("localhost", "root", "")) { 
    echo "Cannot connect to db server"; 
} 
elseif(!mysql_select_db("Disney")) { 
    echo "Cannot select database"; 
} 
else { 
    if(!$rs = mysql_query("SELECT * FROM DisneyCharacters")) { 
      echo "Cannot parse query"; 
    } 
    elseif(mysql_num_rows($rs) == 0) { 
      echo "No records found"; 
    } 
    else { 
//  Name, Movie, year, ShoeSize, FavoriteColor, FavoriteFood, PhoneNumber, CharacterType, FavoriteDrink, Address, FavortieTvShow, School, Age, HouseSqFoot, RelationShip, Rating, CarModel, CarYear, Boyfriend, 
// NumberFriends, CriminalHistory, HappyEnding, FavoriteLocation, AppleDevice, WorkLocation, Weight, RepublicanDemocratic, DressColor, Shampoo, NumberKids) 

      echo "<table width=\"400\" height=\"1\" id=\"sortedtable\" class=\"bordered\" cellspacing=\"0\">\n"; 
      echo "<thead>\n<tr>"; 
      echo "<th>Name </th>"; 
      echo "<th>Movie </th>"; 
      echo "<th>Year </th>"; 
      echo "<th>Shoe Size </th>"; 
      echo "<th>Favorite Color </th>"; 
      echo "<th>Favorite Food </th>"; 
      echo "<th>Phone Number </th>"; 
      echo "<th>Character Type </th>"; 
      echo "<th>Favorite Drink </th>"; 
      echo "<th>Address </th>"; 
      echo "<th>Favorite TvShow </th>"; 
      echo "<th>School </th>"; 
      echo "<th>Age </th>"; 
      echo "<th>HouseSqFoot </th>"; 
      echo "<th>Relationship </th>"; 
      echo "<th>Rating </th>"; 
      echo "<th>Car Model </th>"; 
      echo "<th>Car Year </th>"; 
      echo "<th>Boyfriend </th>"; 
      echo "<th>Number Friends </th>"; 
      echo "<th>Criminal History </th>"; 
      echo "<th>Happy Ending </th>"; 
      echo "<th>Favorite Location </th>"; 
      echo "<th>Apple Device </th>"; 
      echo "<th>Work Location </th>"; 
      echo "<th>Weight</th>"; 
      echo "<th>Republican Democratic </th>"; 
      echo "<th>Dress Color </th>"; 
      echo "<th>Shampoo </th>"; 
      echo "<th>Number Kids </th>"; 
echo "</tr>\n</thead>\n"; 


      echo " <tbody>"; 
      while($row = mysql_fetch_array($rs)) { 


       echo "<tr> 
        <td>$row[Name]&nbsp</td> 
        <td>$row[Movie]&nbsp&nbsp</td> 
        <td>$row[Year]&nbsp</td> 
        <td>$row[ShoeSize]&nbsp</td> 
        <td>$row[FavoriteColor]&nbsp</td> 
        <td>$row[FavoriteFood]&nbsp</td> 
        <td>$row[PhoneNumber]&nbsp</td> 
        <td>$row[CharacterType]&nbsp</td> 
        <td>$row[FavoriteDrink]&nbsp</td> 
        <td>$row[Address]&nbsp</td> 
        <td>$row[FavoriteTvShow]&nbsp</td> 
        <td>$row[School]&nbsp</td> 
        <td>$row[Age]&nbsp</td> 
        <td>$row[HouseSqFoot]&nbsp</td> 
        <td>$row[RelationShip]&nbsp</td> 
        <td>$row[Rating]&nbsp</td> 
        <td>$row[CarModel]&nbsp</td> 
        <td>$row[CarYear]&nbsp</td> 
        <td>$row[Boyfriend]&nbsp</td> 
        <td>$row[NumberFriends]&nbsp</td> 
        <td>$row[CriminalHistory]&nbsp</td> 
        <td>$row[HappyEnding]&nbsp</td> 
        <td>$row[FavoriteLocation]&nbsp</td> 
        <td>$row[AppleDevice]&nbsp</td> 
        <td>$row[WorkLocation]&nbsp</td> 
        <td>$row[Weight]&nbsp</td> 
        <td>$row[RepublicanDemocratic]&nbsp</td> 
        <td>$row[DressColor]&nbsp</td> 
        <td>$row[Shampoo]&nbsp</td> 
        <td>$row[NumberKids]&nbsp</td> 
       </tr>\n"; 



      } 
      echo " </tbody>"; 
      echo "</table><br />\n"; 
    } 

} 
?> 

///的JavaScript

// Drag and drop rows 
$(document).ready(function() { 
    $("#sortedtable").tablesorter({ 
     sortList: [ 
      [0, 0], 
      [2, 1] 
     ], 
     widgets: ['zebra'] 
    }); 
    $("tbody").sortable(); 
    $("tbody").disableSelection(); 
}); 


//Drag and drop columns 
$(document).ready(function() { 
    $("#sortedtable").tablesorter({ 
     sortList: [ 
      [0, 0], 
      [2, 1] 
     ], 
     widgets: ['zebra'] 
    }); 
    $("thead").sortable(); 
    $("thead").disableSelection(); 
}); 
+0

控制台中的任何错误? – Smash

+0

不,我不使用控制台,我使用BBEdit!并在我的本地主机上运行它来查看输出。我认为我的想法是正确的,但它不交换列 – user3474037

+0

以及如何调试javascript错误? – Smash

回答

0

您可以使用该库的数据表。它提供了很多比你问更多,但易于使用和高度可配置的