Created
June 7, 2010 03:02
-
-
Save mrsinguyen/428178 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$sql = "SELECT n.nid, n.vid, n.title, n.uid, u.name, n.created | |
FROM {node} n | |
INNER JOIN {users} u | |
ON u.uid = n.uid | |
WHERE n.type = 'quiz'"; | |
if ($uid != 0) { | |
$sql .= " AND n.uid = %d"; | |
$args[] = $uid; | |
} | |
$sql .= " ORDER BY n.nid DESC"; | |
$dbresult = db_query(db_rewrite_sql($sql), $args); | |
while ($line = db_fetch_array($dbresult)) { | |
$results[$line['nid']] = $line; | |
} | |
return $results; | |
//which becomes, in Drupal 7 | |
$query = db_select('node', 'n'); | |
->fields('n', array('nid', 'vid', 'title', 'created', 'uid', 'type')) | |
->fields('u', array('name')); | |
->join('users', 'u', 'n.uid = u.uid'); | |
->condition('n.type', 'quiz'); | |
->orderBy('nid', 'DESC'); | |
if ($uid != 0) { | |
$query->condition('uid', $uid); | |
} | |
$dbresult = $query->execute(); | |
foreach ($dbresult as $line) { | |
$results[$line['nid']] = $line; | |
} | |
return $results; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment