Created
December 15, 2009 14:23
-
-
Save seanho/256969 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 | |
if ($_GET['type'] == 'archive') | |
{ | |
try | |
{ | |
$db = new PDO("sqlite:talkonly.sqlite"); | |
$sql = "SELECT * FROM play_items ORDER BY list_id DESC, item_id ASC"; | |
$json_output = array(); | |
foreach ($db->query($sql) as $row) | |
{ | |
$json_item = array( | |
"list_id" => $row['list_id'], | |
"item_id" => $row['item_id'], | |
"caption" => $row['caption'], | |
"url" => $row['url'], | |
"short_url" => $row['short_url'] | |
); | |
$json_output[] = $json_item; | |
} | |
$db = null; | |
echo json_encode($json_output); | |
} | |
catch (PDOException $e) | |
{ | |
echo $e->getMessage(); | |
} | |
} | |
else if ($_GET['type'] == 'latest') | |
{ | |
try | |
{ | |
$db = new PDO("sqlite:talkonly.sqlite"); | |
$sql = "SELECT * FROM play_items ORDER BY list_id DESC, item_id ASC"; | |
$json_output = array(); | |
$index = 0; | |
foreach ($db->query($sql) as $row) | |
{ | |
if ($row['item_id'] < $index) break; | |
$json_item = array( | |
"list_id" => $row['list_id'], | |
"item_id" => $row['item_id'], | |
"caption" => $row['caption'], | |
"url" => $row['url'], | |
"short_url" => $row['short_url'] | |
); | |
$json_output[] = $json_item; | |
$index = $index + 1; | |
} | |
$db = null; | |
echo json_encode($json_output); | |
} | |
catch (PDOException $e) | |
{ | |
echo $e->getMessage(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment