Skip to content

Instantly share code, notes, and snippets.

@2803media
2803media / gist:4037615
Created November 8, 2012 08:46
Wordpress featured image
$sql="SELECT * FROM wp_postmeta WHERE `meta_key` LIKE '_thumbnail_id'" ;
$result=mysql_query($sql) or die (mysql_error());
while ($var = mysql_fetch_array($result) ) {
$post_id = $var['post_id'];
$meta_id = $var['meta_id'];
print 'post_id : '.$post_id.'<p></p>';
$sql2="SELECT * FROM wp_posts WHERE `post_parent` = '$post_id' AND post_type = 'attachment' LIMIT 1" ;
 $result2=mysql_query($sql2) or die (mysql_error());
SELECT prenom, COUNT(*) AS nbpre
FROM tablemembres
GROUP BY prenom;
$num_rows = mysql_num_rows($result);
LTRIM pour virer le white space de gauche
mb_strtoupper (majuscule accent eb minuscule)
mysql_real_escape_string
htmlspecialchars
htmlentities
ucwords(strtolower($bar))
ucfirst(strtolower($bar))
$sql2="SELECT *, ( 6371 * acos( cos( radians('$var[latitude]') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('$var[longitude]') ) + sin( radians('$var[latitude]') ) * sin( radians( latitude ) ) ) ) AS distance
FROM cm_gps HAVING distance > 0.01 AND distance < 25 ORDER BY distance LIMIT 0 , 20;";
Fonction mysql de calcul en live :
$sql="SELECT *, get_distance_metres('46', '5.416667', latitude, longitude)
AS proximite
FROM cm_CAF
HAVING proximite < 50000 ORDER BY proximite ASC
LIMIT 10";
ALTER TABLE ma_table MODIFY COLUMN ma_colonne type_de_ma_colonne AFTER autre_colonne
SELECT *FROM `cm_datas` ORDER BY cast(`densite` as decimal) DESC
en sql
SET @rank := 0;
SELECT nom_ville,CODGEO,nbr_habitants,@rank := @rank + 1 AS rank
FROM cm_datas
ORDER BY cast(`nbr_habitants` as decimal) DESC
en php
mysql_query("SET @rank:=0;");
$sql="
SELECT nom_ville,CODGEO,nbr_habitants,@rank := @rank + 1 AS rank
update table_name set field_name = replace(field_name,'string_to_find','string_to_replace');
SELECT DISTINCT ID FROM wp_posts WHERE ID NOT IN (SELECT post_id FROM wp_postmeta WHERE wp_postmeta.meta_key='descriptionspin') AND post_status= 'publish' AND post_type='post'
@2803media
2803media / Supprimer les doublons
Last active January 23, 2019 13:31
mysql doublons
ALTER IGNORE TABLE membre ADD UNIQUE INDEX(nom,prenom);