How would I execute a query equivalent to "select top 10" in couch db?
For example I have a "schema" like so:
title body modified
and I want to select the last 10 modified documents.
As an added bonus if anyone can come up with a way to do the same only per category. So for:
title category body modified
return a list of latest 10 documents in each category.
I am just wandering if such a query is possible in couchdb.
I don't know the best way to title this question but am trying to accomplish the following goal:
When a client logs into their profile, they are presented with a link to download data from an existing database in CSV format. The process works, however, I would like for this data to be 'fresh' each time they click the link so my plan was - once a user has clicked the link and downloaded the CSV file, the database table would 'erase' all of its data and start fresh (be empty) until the next set of data populated it.
My EXISTING CSV creation code:
<?php
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'database';
$table = 'tablename';
$file = 'export';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field'].", ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= '"'.$rowr[$j].'",';
}
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
any ideas?
When does JavaScript evaluate a function? Is it on page load or when the function is called?
The reason why I ask is because I have the following code:
function scriptLoaded() {
// one of our scripts finished loading, detect which scripts are available:
var jQuery = window.jQuery;
var maps = window.google && google.maps;
if (maps && !requiresGmaps.called) {
requiresGmaps.called = true;
requiresGmaps();
}
if (jQuery && !requiresJQuery.called) {
requiresJQuery.called = true;
requiresJQuery();
}
if (maps && jQuery && !requiresBothJQueryGmaps.called) {
requiresBothJQueryGmaps.called = true;
requiresBothJQueryGmaps();
}
}
// asynch download of script
function addScript(url) {
var script = document.createElement('script');
script.src = url;
// older IE...
script.onreadystatechange=function () {
if (this.readyState == 'complete') scriptLoaded.call(this);
}
script.onload=scriptLoaded;
document.getElementsByTagName('head')[0].appendChild(script);
}
addScript('http://google.com/gmaps.js');
addScript('http://jquery.com/jquery.js');
// define some function dependecies
function requiresJQuery() { // create JQuery objects }
function requiresGmaps() { // create Google Maps object, etc }
function requiresBothJQueryGmaps() { ... }
What I want to do is perform asynchronous download of my JavaScript and start at the earliest possible time to begin executing those scripts but my code has dependencies on when the scripted have been obviously downloaded and loaded.
When I try the code above, it appears that my browser is still attempting to evaluate code within my require* functions even before those functions have been called. Is this correct? Or am I misunderstanding what's wrong with my code?
Hi
In my mode I am selecting a field as
$query1 = $this->db->query("SELECT dPassword
FROM tbl_login
WHERE dEmailID='[email protected]'");
How to return dpassword as a variable to my controller
I tried this way return dpassword;
Howdy,
So I have a page with an enormous table in a CRUD interface of sorts. Each link within a span calls a jQuery UI Dialog Form which fetches it's content from another page. When the action taking place (in this case, a creation) has completed, it appends the resulting new data to the table and forces a resort of the table. This all happens within the JS and the DOM.
The problem with this, is that the new table row's CRUD links don't actually trigger the dialog form creation as all the original links in spans are only scanned on document.ready and since I'm not reloading the page, the new links cannot be seen.
Code is as follows:
$(document).ready(function() {
var $loading = $('<img src="/images/loading.gif" alt="Loading">');
$('span a').each(function() {
var $dialog = $('<div></div>')
.append($loading.clone());
var $link = $(this).one('click', function() {
// Dialog Stuff
success: function(data) {
$('#studies tbody').append(
'<tr>' +
'<td><span><a href="./?action=update&study=' + data.study_id + '" title="Update Study">Update</a></span></td>' +
'</tr>'
);
fdTableSort.init(#studies); // This re-sorts the table.
$(this).dialog('close');
}
$link.click(function() {
$dialog.dialog('open');
return false;
});
return false;
});
});
});
Basically, my question is if there is any way in which to trigger a jQuery re-evaluation of the pages links without forcing me to do a browser page refresh?
hi, i have 2 object: user, group that have a relationship many to many
i want create a user and associate some groups to it.
How can i do it?
thanks
I've tried with this. but it's wrong:
user = new User();
List<int> gruppi = new List<int>() {1,2};
utente.Group =db.Group.Where(p => gruppi.Contains(p.GruppoID)
I have noticed some unexpected behaviour when using the jQuery .ready() function, whereby afterwards you can reference an element in the DOM simply by using its ID without prior declaration or assignment:
<html>
<script src="jquery.js"></script>
<script>
$(document).ready(function() {
myowndiv.innerHTML = 'wow!'
});
</script>
<body>
<div id="myowndiv"></div>
</body>
</html>
I would have expected to have to declare and assign myowndiv with document.getElementById("myowndiv"); or $("#myowndiv"); before I could call innerHTML or anything else on it?
Is this behaviour by design? Can anyone explain why? My fear is that if I refactor and end up not using .ready() or even using jQuery at all then my code will fail to execute.
Cheers!
I've created a Dynamic Data project with an Entity Framework model. It works nicely. But, right now it shows all my database tables with the db column names - which aren't always the most friendly (e.g. address_line_1). How can I got about giving these more friendly column titles that will display to the end user?
Hi-- I have a UK date in the format "06/Apr/2010 13:24" that I need to insert into a mysql db date field.
The PHP strtotime function can't handle this string-- has anyone got any ideas other than writing a custom function?
Thanks!
I am attempting to set a cookie to a site using jQuery, ONLY if the user came from a specific site. In this case, lets use -http://referrersite.com- as the site they must come from for the cookie to be created as an example. The cookie value is being stored in a variable and everything up to this point is working fine.
There is a conditional statement checking whether the user came from the referred site, if the cookie exists already and if the cookie doesn't exist and the user did not come from the referred site. If the user came from the referred site the cookie is created and stored in a variable. If the cookie already exists, it is then stored in a variable. If the cookie does not exist and the user did not come from the referred site I am assigning the variable a static string of characters - this is where the issue lies.
When the variable is alerted from the non referred site and no existing cookie, it returns: [object Object], not the static string of characters.
The code I am using is below:
$(document).ready(function() {
var referrer = document.referrer;
if(referrer == "http://referrersite.com") {
$.cookie("code","123456", { expires: 90, path: '/' });
cookieContainer = $.cookie("code");
alert(cookieContainer);
} else if($.cookie("code")) {
cookieContainer = $.cookie("code");
alert(cookieContainer);
} else if($.cookie("code") == null && referrer != "http://referrersite.com") {
cookieContainer = "67890";
alert(cookieContainer);
}
});
Please let me know if there is something I am missing as the code to me looks like it should work.
Thanks!
i`m developing an app for Facebook.
My Code:
function init() {
window.fbAsyncInit = function() {
var appID = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';
FB.init({ appId: appID,
status: true,
cookie: true,
xfbml: true});
login();
};
(function() {
var e = document.createElement("script");
e.async = true;
e.src = "https://connect.facebook.net/en_US/all.js?xfbml=1";
document.getElementById("fb-root").appendChild(e);
}());
};
function login() {
FB.login(function(response) {
if (response.session) {
if (response.perms) {
// user is logged in and granted some permissions.
// perms is a comma separated list of granted permissions
} else {
// user is logged in, but did not grant any permissions
}
} else {
// user is not logged in
}
}, {perms:'read_stream,publish_stream,offline_access'});
};
I want to call the "init" function and after "init" should call the "login" function (open up the Facebook Login Window) automatically.
But i always get "b is null"
FB.provide('',{ui:function(f,b){if(!f....onent(FB.UIServer._resultToken));}}); Error in Firebug.
Can anybody help me?
Does anybody have the same problem?
Thanks
I have a table with
name varchar
address varchar
country varchar
city varchar
.....
to store address of location
example:
name|address|country
HaLong hotel|156 blahblah street|Vietnam
Hotel Ha Long|156 blah blah|Vietnam
Two rows above is duplicate data.
I have a form, when user submit new location. The code need to find akin records to give a message (ex: This location already in db, use it or create new?)
How to make a query to get akin record like this?
there are 2 databases A AND B. i want to transfer data from a table in A TO a table in B. i want to use cursor for this. the duplicate datas when transferring should go to a table called duplicat table. I want a stored procedure to do the above. first i need to connect database A with database B using db link. i want the complete stored procedure. can anyone help plzzzzzzzzzz...........
If e.g. I keep control markup in DB instead of ascx file.
How can I load control from string constant?
(of course if I don't want to save copy to disk)
I want to create a simple CMS for my asp.net-mvc site. Needs some help to start.
Will i save my whole page to db? what if my page contain links like
Url.Content("~/somepage")
When the admin will edit the page he will get the plain link not the Url.Content. How i can handle this in CMS?
Hello all,
Does anyone know of a DB setting in DotNetNuke, where you can configure ALL modules to disable print or maximize&minimize? Just so I don't have to configure every module individually.
How can I make it a default?
Thanks again!
Essentially, I wanted to run a piece of demo code from W3c Offline Webapps page. It looks like that:
var db = window.openDatabase("notes", "", "The Example Notes App!", 1048576);
Firefox 3.5, IE8 and Chrome do not seem to get it. Is there anybody out there that actually wrote support for that? Or is this wishful thinking about 'the standard of the future'?
I am working on cleaning up a mess that another programmer started. The created 2 identical databases for different locations but that obviously caused major issues. They are using cakePHP and there are quite a few relationships. I am pretty sure I will have to write a script to import that data from on DB to the other and keep all the relationships but was wondering if there is an easier way to do it.
i am downloading files from server using WinSCP.Is it possible to write a query to download a large database using mysql query? Or using any other method
i have tried with this code but i am not able to get the whole database structure
<?php
if(file_exists('backup_sql/my_backup.zip'))
{
unlink('backup_sql/my_backup.zip');
}
$tables='*';
$host='MY HOST NAME';
$user='MY_USERNAME';
$pass='MYPASSWORD';
$name='MY_DB_NAME';
$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);
//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
$return='';
//cycle through
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);
//$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
//$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}
$rand_var=time();
$files_to_zip = array(
"'backup_sql/db-backup-'.$rand_var.'.sql'",
);
$name = 'db-backup-'.$rand_var.'.sql';
$data = $return;
?>
any one please help me... thank you
Hi
This is what i have in my view page
<td width=""><input type="text" name="txtUserName" id="txtUserName" /></td>
<td><input type="button" name="CheckUsername" id="CheckUsername" value="Check Availablity"
onclick="Check_User_Name();"/></td>
Onclick of the button the Check_User_Name function in my ajax.js loads
This is the Check_User_Name function
function Check_User_Name(source)
{
var UserName = document.getElementById('txtUserName').value;
if(window.ActiveXObject)
User_Name = new ActiveXObject("Microsoft.XMLHTTP");
else if(window.XMLHttpRequest)
User_Name = new XMLHttpRequest();
var URL = newURL+"ssit/system/application/views/ssitAjax.php";
URL = URL +"?CheckUsername="+UserName;
User_Name.onreadystatechange = User_Name_Fun;
User_Name.open("GET",URL,true);
User_Name.send(null);
}
function User_Name_Fun()
{
document.getElementById('User_div').innerHTML=User_Name.responseText;
}
Then I can have the value in echo username then the $result has all the user name
Hows can i checkIsavailablity of username from here
if(($_GET['CheckUsername']!="") || (isset($_GET['CheckUsername'])))
{
echo $UserName = $_GET['CheckUsername'];//echo username
$_SESSION['state'] = $State;
$queryres = "SELECT dUser_name FROM tbl_login
WHERE dIsDelete='0'";
$result = mysql_query($queryres,$cn) or die("Selection Query Failed !!!");
hi ,
I want to use jquery inside data returnd by ajax using " innerHtml" ..
look here ,
<a href=\"#\"
onclick=\"$.post('". $url ."', {'t' : 't'}, function(data){
$('content_rows').attr('innerHTML',data);}); " . $this->js_rebind .";return false;\">"
$text .'</a>';
this link makes moving between the pages by ajax "by reloading the div that contains the data" ,
without - of course - reloading whole page .
like this :
<div id="content_rows">
rows from mysql database
</div>
now everything is Ok , but ,
I use " detailsRow Plugin " like this :
<script type="text/javascript">
$(document).ready(function() {
$('#rows').detailsRow('admin/blog/detailsRow',{
data:{"id":"id"} ,
dataType: "script"
});
});
</script>
this plugin makes every TR/Row in the table get more details by click (+-) .. go there :
http://webworkflow.co.uk/plugins/detailsRow/
now this plugin works fine in the frist page ( before reload the div by jquery )
but after reloading the div and in the other pages or also when I go back to the frsit page
it dos`nt work ..
I put the code inside content_rows div like this :
<div id="content_rows">
<script type="text/javascript">
$(document).ready(function() {
$('#rows').detailsRow('admin/blog/detailsRow',{
data:{"id":"id"} ,
dataType: "script"
});
});
</script>
</div>
but also doesnt work ..
sorry I`m beginner in jQuery ..
thanks ..
Currently im just using something like:
in the DB Table:
access: home,register,login
and then in each page:
if(!Functions::has_rights('content'))
{
Functions::noAccess();
}
is there more efficient way to do it, php & MySQL? i may want to gain access even to several parts a page, for example: user can read a page, but doesnt comment to it, and I dont want to build a separate system to each module.
Thanks in advanced, Tal.
Using Git or Mercurial, how would you know when you do a clone or a pull, no one is checking in files (pushing it)? It can be important that:
1) You never know it is in an inconsistent state, so you try for 2 hours trying to debug the code for what's wrong.
2) With all the framework code -- potentially hundreds of files -- if some files are inconsistent with the other, can't the rake db:migrate or script/generate controller cause some damage or inconsistencies to the code base?