Skip to content

Instantly share code, notes, and snippets.

@sudhanshuraheja
Created May 24, 2011 10:39
Show Gist options
  • Save sudhanshuraheja/988500 to your computer and use it in GitHub Desktop.
Save sudhanshuraheja/988500 to your computer and use it in GitHub Desktop.
Random PHP file
<?php
// This is how mixed up the tables get in even the simpler projects
// If you change the structure of the database, life sudden
$query .= '
SELECT
summary.recordlabel AS recordid,
summary.artist AS artistid,
summary.album AS albumid,
summary.song AS songid,
summary.video AS videoid,
users.recordlabelname AS recordlabelname,
artists.name AS artistname,
albums.name AS albumname,
songs.name AS songname,
videos.name AS videoname,
';
$query .= ' summary.date, summary.' . $group . ' AS f';
$query_generic = 'SELECT * ';
if($type == 'sales') {
$query .= ' , SUM(summary.amount) AS total, SUM(summary.amount_admin) AS total_admin, SUM(summary.amount_label) AS total_label ';
if($perms == 1) {
$query_generic .= ' , SUM(summary.amount) AS total ';
} else if($perms == 5) {
$query_generic .= ' , SUM(summary.amount_label) AS total';
} else if($perms == 10) {
$query_generic .= ' , SUM(summary.amount_admin) AS total';
}
} else {
$query .= ' , COUNT(summary.id) AS total ';
$query_generic .= ' , COUNT(summary.id) AS total ';
}
$query .= '
FROM
(
(
(
(
summary LEFT JOIN users ON users.id = summary.recordlabel
)
LEFT JOIN artists ON artists.id = summary.artist
)
LEFT JOIN albums ON albums.id = summary.album
)
LEFT JOIN songs ON songs.id = summary.song
)
LEFT JOIN videos ON videos.id = summary.video
';
$query_generic .= ' FROM summary ';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment