domingo, 3 de noviembre de 2013

php elminar duplicados de un array

<?php
 
 $lista = array(2010,2009,1999,2010,2010,2008,2010);
 $lista = array_unique($lista);
 $lista = array_values($lista);
 
?>
 
 
 
 
. 

mysql eliminar duplicados dejando una muestra


CREATE TABLE `prueba` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `titulo` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

--
-- Volcar la base de datos para la tabla `prueba`
--

INSERT INTO `prueba` VALUES (1, 'titulo1');
INSERT INTO `prueba` VALUES (2, 'titulo2');
INSERT INTO `prueba` VALUES (3, 'titulo1');
INSERT INTO `prueba` VALUES (4, 'titulo3');
INSERT INTO `prueba` VALUES (5, 'titulo1');
INSERT INTO `prueba` VALUES (6, 'titulo2');
INSERT INTO `prueba` VALUES (7, 'titulo1');

//******************************


NOTA: COPIADO DE
http://andalinux.wordpress.com/2013/04/15/sql-eliminar-entradas-duplicadas-dejando-una-de-muestra/



Dejar la entrada más antigua

Si queremos eliminar todas las entradas duplicadas dejando la primera aparición (la más vieja, la que tiene menor ID) lanzaremos la siguiente sentencia SQL





DELETE n1
FROM prueba n1, prueba n2
WHERE n1.titulo = n2.titulo
AND n1.id > n2.id;

Dejar la última aparición

Si queremos eliminar todas las entradas duplicadas menos la más reciente (la más nueva, la que tiene mayor ID) lanzaremos la siguiente consulta SQL
 




DELETE n1
FROM prueba n1, prueba n2
WHERE n1.titulo = n2.titulo
AND n1.id < n2.id;
NOTA: Observa que el único cambio ha sido n1.id < n2.id en lugar de n1.id > n2.id

martes, 29 de octubre de 2013

php suma y resta horas

date_default_timezone_set('Europe/Madrid');

$Hora = Time(); // Hora actual  
echo date('H:i:s',$Hora);     

$Hora = Time() + (60 *60 * -1);  
echo "<br>";
echo date('H:i:s',$Hora); //  -1 hora

$Hora = Time() + (60 *60 * 2);  
echo "<br>";
echo date('H:i:s',$Hora); //  +2 hora


....  O TAMBIEN

$Hora = strtotime('14:00:01') + (60 *60 * -1); ;
echo date('H:i:s',$Hora);   


.... O EN FUNCION

//***************************************************
function sumaRestaHoras($hora, $incremento)
{
$hora = strtotime($hora) + (60 *60 * $incremento);

return date('H:i:s',$hora);
}

echo sumaRestaHoras('14:00:01',-5);
 






.

php suma a una fecha un numero de dias

function suma_fechas($fecha,$ndias)
{
    if (preg_match("/[0-9]{1,2}\/[0-9]{1,2}\/([0-9][0-9]){1,2}/",$fecha))
    list($dia,$mes,$anyo)=split("/", $fecha);

    if (preg_match("/[0-9]{1,2}-[0-9]{1,2}-([0-9][0-9]){1,2}/",$fecha))
    list($dia,$mes,$anyo)=split("-",$fecha);

    $nueva = mktime(0,0,0, $mes,$dia,$anyo) + $ndias * 24 * 60 * 60;
    $nuevafecha=date("d/m/Y",$nueva);

    return ($nuevafecha);
}

lunes, 28 de octubre de 2013

JAVASCRIPT saber la altura del body


var alto=window.innerHeight;



 


//***
// si queremos cambiar la altura de un DIV por ejemplo.


alto=alto-500;
document.getElementById("div1").style.height=alto+'px';

viernes, 14 de junio de 2013

CAST en MySql

  • BINARY[(N)]
  • CHAR[(N)]
  • DATE
  • DATETIME
  • DECIMAL[(M[,D])]
  • SIGNED [INTEGER]
  • TIME
  • UNSIGNED [INTEGER]

 // velocidad es string y lo pasamos a INT

SELECT max(CAST(velocidad AS UNSIGNED)) FROM coches
 
 
// para decimal
 
SELECT max(CAST(velocidad AS DECIMAL(2,2))) FROM coches 
 
si la maxima velocidad fuera 145.322456 saldria 45.32

//**
 
SELECT max(CAST(velocidad AS DECIMAL(3,2))) FROM coches 
 
si la maxima velocidad fuera 145.322456 saldria 145.32


domingo, 2 de junio de 2013

reemplazar todos los caracteres en javascript

function replaceAll( text, busca, reemplaza )
{
    while (text.toString().indexOf(busca) != -1)
        text = text.toString().replace(busca,reemplaza);
    return text;
}




.

sábado, 20 de abril de 2013

mover una columna de una tabla mysql

ALTER TABLE alumnos MODIFY COLUMN apellidos VARCHAR(255) AFTER nombre








.

martes, 19 de marzo de 2013

solucion appserv phpmyadmin no funciona en windows vista

1) instalar el appserv (en mi caso appserv-win32-2.6.0)
2) ir a la carpeta C:\AppServ\www\phpMyAdmin
3) editar el fichero config.inc.php

y cambiar la linea donde pone

$cfg['Servers'][$i]['host']          = 'localhost';
por
$cfg['Servers'][$i]['host']          = '127.0.0.1';

4) reiniciar el apache

y listo !! ;)


---------------------------------------
sacado de aquí
---------------------------------------

Recently I published an article about Windows Vista Home Premium and the “problems” I was running into when installing my programs. Well, this time I run into another problem when I installed appserv-win32-2.6.0 . Everything seemed to work just fine, Apache was working well, but when I tried opening PhpMyAdmin for some reason it was displaying a blank page after I entered my login information.

Method #1

The solution to this blank page problem is fairly easy. Simply modify this line in the phpmyadmin/config.inc.php
$cfg['Servers'][$i]['host']          = 'localhost';
to this:
$cfg['Servers'][$i]['host']          = '127.0.0.1';
In the above code, you’re changing your name server to 127.0.0.1 in order to use TCP/IP connection. After this, you should be able to see your PhpMyAdmin page by opening in your browser the address http://127.0.0.1/PhpMyAdmin
Hope this helps!
Note: Whenever you specify “localhost” or “localhost:port” as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use “127.0.0.1″ instead of “localhost”. If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as Runtime Configuration in your PHP configuration and leave the server field blank.

UPDATE Dec 15, 2010:

Doing further research on this subject, this problem seems to be caused by a PHP bug #45150. The problem seems to be with Windows resolving localhost, more specifically localhost resolving to ::1 when IPv6 is enabled. If you have Windows Vista or Windows 7 it’s most likely you have IPV6 enabled by default.

Method #2

1. Go to Network Connections-> Properties and on local area connection->uncheck IPV6.
2.Open up \%windir%\system32\drivers\etc\ with a text editor and comment out this line:
::1 localhost
and prefix it:
#::1 localhost
This fix will help the loopback interface 127.0.0.1 point to localhost.
Save it and your PHP/MySQL connections will immediately begin working.
This is another way of fixing this problem. Both methods will work, but I’d recommend to follow this last method over the first one since it’s updated and it solves the localhost issue in a more efficient way now that we have detected the source of the problem.
Big thanks: to my readers Joberror, Adrian, Brandon and everyone else for your contributions.





sábado, 16 de marzo de 2013

javascript ir a una pagina

<script>
//************************
function irAUrl(pag)
{
    location.href=pag;
}

</script>

<input type="button" value="IR A GOOGLE" onclick="irAUrl('http://www.google.es')">


domingo, 10 de marzo de 2013

Reemplazando texto en MySQL


UPDATE indiakaarticulos SET peso = REPLACE(peso,'gr.','');