Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getTasksReport($rmId, $stage, $mmcName) {
- $rmCondition = $rmId ? 'mud.manager_id = :rmId' : 'TRUE';
- $stageCondition = $stage ? 't.stage_id = :stageId' : 'TRUE';
- $mmcCondition = $mmcName ? 'mmcs.username = :mmcName' : 'TRUE';
- $sql = "
- SELECT
- mmcs.id AS mmc_id,
- mmcs.username AS mmcname,
- mud.band_name AS mmc_name,
- t.id AS task_id,
- t.name AS task,
- t.stage_id AS stage,
- t.role_id,
- tl.id AS task_log_id,
- mr.role,
- u.id AS user_id,
- u.username AS username,
- COALESCE(cud.full_name, bud.band_name) AS user_name,
- DATE_FORMAT(tl.completed_on, '%d-%m-%Y %T') AS completed_on,
- tl.url AS url,
- mud.manager_id AS rm_id
- FROM users AS mmcs
- INNER JOIN banduserdetails AS mud ON mud.user_id = mmcs.id
- LEFT JOIN tasks AS t ON 1
- LEFT JOIN task_log AS tl ON tl.task_id = t.id AND tl.mmc_id = mmcs.id
- LEFT JOIN mmc_roles AS mr ON mr.id = t.role_id
- LEFT JOIN users AS u ON u.id = tl.user_id
- LEFT JOIN communityuserdetails AS cud ON cud.user_id = u.id
- LEFT JOIN banduserdetails AS bud ON bud.user_id = u.id
- WHERE mmcs.user_type = 'mmc'
- AND $rmCondition
- AND $stageCondition
- AND $mmcCondition
- ORDER BY mmcs.id, t.stage_id, t.role_id, t.task_order
- ";
- $pdo = new PDO(.....);
- $stmt = $pdo->prepare($sql);
- $rmId and $stmt->bindValue('rmId', $rmId); // (1)
- $stage and $stmt->bindValue('stageId', $stage); // (2)
- $mmcName and $stmt->bindValue('mmcName', $mmcName); // (3)
- $stmt->execute();
- return $stmt->fetchAll();
- }
- db_exec ("SELECT ...");
- $SQL = "SELECT ...";
- $result = db_exec ($SQL);
- $weblog = new Weblog(); // create an empty object to work with.
- $weblog->Author = 'SchizoDuckie'; // mapped internally to strAuthor.
- $weblog->Title = 'A test weblog';
- $weblog->Story = 'This is a test weblog!';
- $weblog->Posted = date("Y-m-d H:i:s");
- $weblog->Save(); // Checks for any changed values and inserts or updates into DB.
- echo ($weblog->ID) // outputs: 1
- $reply = new Reply();
- $reply->Author = 'Some random guy';
- $reply->Reply = 'w000t';
- $reply->Posted = date("Y-m-d H:i:s");
- $reply->IP = '127.0.0.1';
- $reply->Connect($weblog); // auto-saves $reply and connects it to $weblog->ID
- $weblog = new Weblog(1); //Fetches the row with primary key 1 from table weblogs and hooks it's values into $weblog;
- echo("<h1>{$weblog->Title}</h1>
- <h3>Posted by {$weblog->Author} @ {$weblog->Posted}</h3>
- <div class='weblogpost'>{$weblog->Story}</div>");
- // now fetch the connected posts. this is the real magic:
- $replies = $weblog->Find("Reply"); // fetches a pre-filled array of Reply objects.
- if ($replies != false)
- {
- foreach($replies as $reply)
- {
- echo("<div class='weblogreply'><h4>By {$reply->Author} @ {$reply->Posted}</h4> {$reply->Reply}</div>");
- }
- }
- class Weblog extends dbObject
- {
- function __construct($ID=false)
- {
- $this->__setupDatabase('blogs', // database table
- array('ID_Blog' => 'ID', // database field => mapped object property
- 'strPost' => 'Story', // as you can see, database field strPost is mapped to $this->Story
- 'datPosted' => 'Posted',
- 'strPoster' => 'Author',
- 'strTitle' => 'Title',
- 'ipAddress' => 'IpAddress',
- 'ID_Blog', // primary table key
- $ID); // value of primary key to init with (can be false for new empty object / row)
- $this->addRelation('Reaction'); // define a 1:many relation to Reaction
- }
- }
- $sql = "SELECT tbl1.col1, tbl1.col2, tbl2.col1, tbl2.col2"
- . " FROM Table1 tbl1"
- . " INNER JOIN Table2 tbl2 ON tbl1.id = tbl2.other_id"
- . " WHERE tbl2.id = ?"
- . " ORDER BY tbl2.col1, tbl2.col2"
- . " LIMIT 10, 0";
- $sql = (string) View::factory('sql/myfile');
- $sql = file_get_contents("myfile.sql");
- $query = "SELECT "
- . " foo, "
- . " bar "
- . "FROM "
- . " mytable "
- . "WHERE "
- . " id = $userid";
Add Comment
Please, Sign In to add comment