Мне удалось заставить строки перетащить и упасть в таблицу, но у меня возникают трудности с столбцами. Мой javascript, похоже, не работает. Любая помощь будет оценена
<?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] </td> <td>$row[Movie]  </td> <td>$row[Year] </td> <td>$row[ShoeSize] </td> <td>$row[FavoriteColor] </td> <td>$row[FavoriteFood] </td> <td>$row[PhoneNumber] </td> <td>$row[CharacterType] </td> <td>$row[FavoriteDrink] </td> <td>$row[Address] </td> <td>$row[FavoriteTvShow] </td> <td>$row[School] </td> <td>$row[Age] </td> <td>$row[HouseSqFoot] </td> <td>$row[RelationShip] </td> <td>$row[Rating] </td> <td>$row[CarModel] </td> <td>$row[CarYear] </td> <td>$row[Boyfriend] </td> <td>$row[NumberFriends] </td> <td>$row[CriminalHistory] </td> <td>$row[HappyEnding] </td> <td>$row[FavoriteLocation] </td> <td>$row[AppleDevice] </td> <td>$row[WorkLocation] </td> <td>$row[Weight] </td> <td>$row[RepublicanDemocratic] </td> <td>$row[DressColor] </td> <td>$row[Shampoo] </td> <td>$row[NumberKids] </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(); });
Вы можете использовать библиотеку DataTables. Он обеспечивает намного больше, чем вы просите, но прост в использовании и настраивается