Ver Mensaje Individual
  #12 (permalink)  
Antiguo 25/04/2012, 16:17
Avatar de IsaBelM
IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: como mostrar un registro en primer lugar

creo que lo que quieres es hacer como un panel de administrador. yo esto lo hago con ajax
Cita:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<head>
<meta http-equiv="Content-Type" content="application/xhtml; charset=utf-8" />
<title></title>
<style type="text/css">
span {
background-color: red;
color: yellow;
cursor: pointer;
}
</style>

<script type="text/javascript">
Object.prototype.subir = function() {

if (this.previousElementSibling === null) {
alert('no es posible subir este nodo');
return false;

} else {

var n = document.getElementById('nodos');
//this.attributes.posact.value = this.previousElementSibling.attributes.posact.valu e;
//this.previousElementSibling.attributes.posact.valu e = parseInt(this.attributes.posact.value)+1;

this.setAttribute('posact', this.previousElementSibling.getAttribute('posact') );
this.previousElementSibling.setAttribute('posact', parseInt(this.getAttribute('posact'))+1);

n.insertBefore(this, this.previousElementSibling);

//alert('posicion inicial --> ' + this.getAttribute('posini') + ' posición actual --> ' + this.getAttribute('posact') +'\nposicion inicial --> ' + this.nextElementSibling.getAttribute('posini') + ' posición actual --> ' + this.nextElementSibling.getAttribute('posact'));

return "param[]=" + this.getAttribute('posact') + "&param[]=" + this.getAttribute('posini') + "&param[]=" + this.nextElementSibling.getAttribute('posact') + "&param[]=" + this.nextElementSibling.getAttribute('posini');

}
}




Object.prototype.bajar = function() {

if (this.nextElementSibling === null) {
alert('no es posible bajar este nodo');
return false;

} else {

var n = document.getElementById('nodos');
//this.attributes.posact.value = this.nextElementSibling.attributes.posact.value;
//this.nextElementSibling.attributes.posact.value = parseInt(this.attributes.posact.value)-1;

this.setAttribute('posact', this.nextElementSibling.getAttribute('posact'));
this.nextElementSibling.setAttribute('posact', parseInt(this.getAttribute('posact'))-1)

n.insertBefore(this.nextElementSibling, this);

//alert('posicion inicial --> ' + this.getAttribute('posini') + ' posición actual --> ' + this.getAttribute('posact') +'\nposicion inicial --> ' + this.previousElementSibling.getAttribute('posini') + ' posición actual --> ' + this.previousElementSibling.getAttribute('posact') );

return "param[]=" + this.getAttribute('posact') + "&param[]=" + this.getAttribute('posini') + "&param[]=" + this.previousElementSibling.getAttribute('posact') + "&param[]=" + this.previousElementSibling.getAttribute('posini') ;

}
}



function fnc(metodo){
var data = (function(){return metodo})();
if(data == false) return;

ajax = new XMLHttpRequest();
ajax.open('POST', 'NODOS_MOVER.php', false);
ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
ajax.send(data);
return;
}
</script>

</head>
<body>
<div id="nodos">
<?php

$sql = mysql_query("SELECT * FROM ordenarregistros ORDER BY posicionActual asc") or die(mysql_error());

if(mysql_num_rows($sql)>0){
while($registros = mysql_fetch_assoc($sql)){
?>
<p posact="<?php echo $registros['posicionActual']?>" posini="<?php echo $registros['id']?>">
<?php echo $registros['cuerpo']?> <span onclick="return fnc(this.parentNode.subir())">Subir</span> - <span onclick="return fnc(this.parentNode.bajar())">Bajar</span>
</p>


<?php
}
}
mysql_free_result($sql);
mysql_close($conexion);
?>

</body>
</html>
Cita:
<?php
$datos = array($_POST["param"]);

$sql = mysql_query("UPDATE ordenarregistros SET posicionActual = '" .$datos[0][0]. "' WHERE id = '" .$datos[0][1]. "'");
$sql = mysql_query("UPDATE ordenarregistros SET posicionActual = '" .$datos[0][2]. "' WHERE id = '" .$datos[0][3]. "'");

mysql_close($conexion);
?>
estructura de la tabla
Cita:
CREATE TABLE IF NOT EXISTS `ordenarregistros` (
`id` int(11) NOT NULL auto_increment,
`posicionActual` int(11) NOT NULL,
`cuerpo` text collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
)
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}