0
if(!$_GET){
    echo "{'success':false, 'error':'No query parameters submitted'}";
    return;
}

// 1. Include the SimpleDB class if it does not exist
if (!class_exists('SimpleDB'))require_once('sdb.php');  

// 2. Set awsAccessKey and awsSecretKey to your values
require_once('config.inc.php');  

// create connection
$sdb = new SimpleDB(awsAccessKey, awsSecretKey);  
$condition = "";
$status = "";

//$params = json_decode(stripslashes($_POST['hash']));
$params = $_GET;
foreach($params as $key => $value){
    $condition .= " " . $key . " = '" . $value . "' and" ;      
}

$condition = preg_replace('/and$/', "", $condition);

$query = "select * from $domain";

if($condition!= " _empty_ = '' "){
    $query .= " where $condition ";
}

$fileHash = '{';
if($files = $sdb->select($domain, $query)){
    $status = 'true';
    $fileHash .= "'files' : ".json_encode($files).", ";
}else{
    $status = 'false';
    $fileHash .= "'files' : [], ";
    $fileHash .= "'error' : 'No records retrieved from SimpleDB ".json_encode($sdb->ErrorCode)."', ";
}
$fileHash .= "'success':".$status."}";
echo $fileHash;

my json response { 'files': [{ "Name": "4cf0dadfddfe6", "Attributes": { "title": "Earrings!", "file_size": "135023", "url": "http:\/\/dtzhqpwfdzscm.cloudfront.net\/4cf0dadfddfe6.jpg", "file_name": "4cf0dadfddfe6.jpg", "time_stamp": "1290853092", "file_type": "image\/jpeg", "content_obj_type": "upload", "thumb": "http:\/\/dtzhqpwfdzscm.cloudfront.net\/4cf0dadfde32b.jpg", "width": "176.04166666666669", "height": "171", "userid": "4", "gibid": "54", "contentid": "4cf0dadfddfe6", "qqfile": "il_570xN.182320055.jpg", "original_name": "il_570xN.182320055.jpg", "y": "72", "x": "535", "on_floor": "false", "success": "true", "gibview": "O", "avatar_url": "", "crop_url": "" } }], 'success': true }

i want to sort by time_stamp how can i do this .? or any good article for learning s3 database please suggest.

XMen
  • 29,384
  • 41
  • 99
  • 151

3 Answers3

0

Like in any other sql dialect - sorting can be performed with ORDER BY clause:

ORDER BY time_stamp

http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/index.html?UsingSelect.html

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • : 'No records retrieved from SimpleDB "InvalidSortExpression this error is coming , what is the problem ? – XMen Nov 30 '10 at 07:31
  • @Rahul Mehta: how could i say if i don't see query? – zerkms Nov 30 '10 at 07:39
  • select * from second where gibid = '54' and gibview = 'O' order by time_stamp, this is the query – XMen Nov 30 '10 at 07:42
  • @Rahul Mehta: is there a `time_stamp` field in the table? – zerkms Nov 30 '10 at 07:59
  • @zerkms as i am new to amazon simple db how can i check that there is field time_stamp in the table – XMen Nov 30 '10 at 08:10
  • @Rahul Mehta: to be clear - I don't know ;-) I just googled it for your question and read several pages in documentation ;-) – zerkms Nov 30 '10 at 11:07
0

Amazon db has null values so by giving time_stamp is not null condition have solved the problem.

XMen
  • 29,384
  • 41
  • 99
  • 151
0

Note that with SimpleDB you can only ORDER BY an attribute that you used in the WHERE clause. That's why

select * from second where gibid = '54' and gibview = 'O' order by time_stamp

doesn't work. Adding "time_stamp is not null" to the WHERE clause makes time_stamp available for ORDER BY.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183