Weil man keine Datensätze aus der Tabelle löschen kann, die man gerade abfragt, braucht man eine temporäre Tabelle. Hier werden die doppelten Daten zwischengespeichert.
CREATE TABLE temp AS (
SELECT tabelle2.id FROM doppelte tabelle1, doppelte tabelle2
WHERE tabelle1.id != tabelle2.id
AND tabelle1.feld_a = tabelle2.feld_a
AND tabelle1.feld_b = tabelle2.feld_b
AND tabelle1.feld_c = tabelle2.feld_c
AND tabelle1.id < tabelle2.id
)
Jetzt die Daten löschen
DELETE FROM doppelte WHERE id IN (SELECT * FROM temp);
DROP TABLE temp;
2012
doppelte Datensätze aus einer MySql Tabelle löschen
2012
mit mysql alle doppelten Datensätze anzeigen
SELECT
SOURCE.*
FROM
mytable AS SOURCE,
(
SELECT field_1, field_2 -- alle Group-Felder
FROM mytable
-- alle Group-Felder
GROUP BY field_1, field_2
-- nur jene auswählen die mehr als ein Datensatz haben
HAVING COUNT(*) > 1
) AS FILTER
WHERE
-- alle Group-Felder verknüpfen
FILTER.field_1 = SOURCE.field_1
AND FILTER.field_2 = SOURCE.field_2
2011
Bitoperator Vergleich
Wenn $this->numberOfRows gerade ist, wird die if Anweisung durchgeführt:
$delimiter = 1;
if( $this->numbersOfRow & 1 )
{
$delimiter = 2;
}
2010
delete of .svn directories
find . -type d -name .svn |xargs rm -rf
2010
2010
flush memcached
echo "flush_all" | nc localhost 11211
2010
enum Felder mit cakephp auslesen
Dieser Code kommt in das app_model.php
/**
* Get Enum Values
* Snippet v0.1.3
* http://cakeforge.org/snippet/detail.php?type=snippet&id=112
*
* Gets the enum values for MySQL 4 and 5 to use in selectTag()
*/
function getEnumValues($columnName=null, $respectDefault=false) {
if ($columnName==null) { return array(); } //no field specified
//Get the name of the table
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$tableName = $db->fullTableName($this, false);
//Get the values for the specified column (database and version specific, needs testing)
$result = $this->query("SHOW COLUMNS FROM {$tableName} LIKE '{$columnName}'");
//figure out where in the result our Types are (this varies between mysql versions)
$types = null;
if ( isset( $result[0]['COLUMNS']['Type'] ) ) { $types = $result[0]['COLUMNS']['Type']; $default = $result[0]['COLUMNS']['Default']; } //MySQL 5
elseif ( isset( $result[0][0]['Type'] ) ) { $types = $result[0][0]['Type']; $default = $result[0][0]['Default']; } //MySQL 4
else { return array(); } //types return not accounted for
//Get the values
$values = explode("','", preg_replace("/(enum)\('(.+?)'\)/","\\2", $types) );
if($respectDefault){
$assoc_values = array("$default"=>Inflector::humanize($default));
foreach ( $values as $value ) {
if($value==$default){ continue; }
$assoc_values[$value] = Inflector::humanize($value);
}
}
else{
$assoc_values = array();
foreach ( $values as $value ) {
$assoc_values[$value] = Inflector::humanize($value);
}
}
return $assoc_values;
} //end getEnumValues
In dem Controller holt man sich die Werte dann so:
$this->set('value', $this->Model->getEnumValues('field'));
und in der View kommt das hinein:
echo $form->input('value', array('options' => $kind, 'label' => 'value:'));
2010
die neuesten Einträge mit cakephp bekommen
function getNewest( $limit = 50 ) {
$data = $this->find('all',
array(
'order' => $this->name .'.id DESC',
'limit' => $limit)
);
return $data;
}
2009
A piece of information
![]() |
People in Palestine are trapped inside a Wall. “We are human beings, just like you, with a sense of humour, and lust for life”.The text on the image is inside the wall. No Photoshop. |
gefunden auf: http://flowplayer.org/tools/release-notes/
2009
15 CakePHP Tipps
nuts and bolts hat eine Liste mit einigen Tipps zu CakePHP zusammengestellt.
zu den Cake Tipps
