y quiero que haga lo siguiente:(casi igual a esto, pero que se puedan editar y actualizar las celdas)
1.- que muestre en una tabla los datos de una base de datos en 4 colunmas: 1=id, 2=Nombre, 3= apellido y 4= edad
2.- que al darle click a la cabecera de la colunma me los ordene por nombre, apellido o edad, en Ascendente, y al darle click otra vez me los ordenes en descendente
3.- que la informacion de cada celda se pueda editar y que tenga un boton a un lado que si le das click se actualiza la informacion en la base de datos
4.- un boton para guardar todo global
es todo hasta ahorita llevo esto pero no puedo hacer que ordene las columnas:
Cualquier ayuda sera muy agradecida!!!:
Código PHP:
<!DOCTYPE html>
<html>
<body>
<form action="insert.php" method="post">
Firstname: <input type="textarea" name="firstname"><br>
Lastname: <input type="text" name="lastname"><br>
Age: <input type="text" name="age">
<input type="submit">
</form>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
echo "<table border='1'>
<tr>
<th>ID No.</th>
<th><form><input type='submit' name='orderbyfirstname' value='First Name'></button></form></th>
<th></th>
<th><form><input type='submit' name='orderbylastname' value='Last Name'></button></form></th>
<th></th>
<th><form><input type='submit' name='orderbyage' value='Age'></button></form></th>
<th></th>
</tr>";
//Ordena por id
while($row = mysql_fetch_array($result))
{
echo "<tr>";
//echo"<td>" . $row['No'] . "</td>";
echo "<td>". $row['Id'] . "</td>";
echo "<td><textarea>" . $row['FirstName'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "<td><textarea>" . $row['LastName'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "<td><textarea>" . $row['Age'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "</tr>";
}
//Ordena por FirstName
if(isset($_POST['orderbyfirstname'])){
$OrderByFirstname = mysql_query("SELECT * FROM persons ORDER BY firstname");
while ($row = mysql_fetch_array($result, $OrderByFirstname)) {
echo "<tr>";
//echo"<td>" . $row['No'] . "</td>";
echo "<td>". $row['Id'] . "</td>";
echo "<td><textarea>" . $row['FirstName'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "<td><textarea>" . $row['LastName'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "<td><textarea>" . $row['Age'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "</tr>";
}
}
//Ordena por Lastname
if(isset($_POST['orderbylastname'])){
$OrderByLastName = mysql_query("SELECT * FROM persons ORDER BY lastname");
while ($row = mysql_fetch_array($result,$OrderByLastName)) {
echo "<tr>";
//echo"<td>" . $row['No'] . "</td>";
echo "<td>". $row['Id'] . "</td>";
echo "<td><textarea>" . $row['FirstName'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "<td><textarea>" . $row['LastName'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "<td><textarea>" . $row['Age'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "</tr>";
}
}
//Ordena por Age
if(isset($_POST['orderbyage'])){
$OrderByAge = mysql_query("SELECT * FROM persons ORDER BY age");
while ($row = mysql_fetch_array($result,$OrderByAge)) {
echo "<tr>";
//echo"<td>" . $row['No'] . "</td>";
echo "<td>". $row['Id'] . "</td>";
echo "<td><textarea>" . $row['FirstName'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "<td><textarea>" . $row['LastName'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "<td><textarea>" . $row['Age'] . "</textarea></td>";
echo"<td><p>B/S</p></td>";
echo "</tr>";
}
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>
Código PHP:
<!DOCTYPE HTML>
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con){
die('No se pudo conectar con la base de datos: '. mysql_error());
}
mysql_select_db("my_db",$con);
$sql = "INSERT INTO Persons (FirstName, LastName, Age)
VALUES('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if(!mysql_query($sql, $con)){
die('Error: '. mysql_error());
}
echo "1 record added";
mysql_close($con);
?>