Skip to content

Instantly share code, notes, and snippets.

@seanho
Created December 15, 2009 14:23
Show Gist options
  • Save seanho/256969 to your computer and use it in GitHub Desktop.
Save seanho/256969 to your computer and use it in GitHub Desktop.
<?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