I am working on a google Map Api using fusion. I have multiple search queries and want them to filter the results. At the moment they overrule each other and don't work together the filter the results. The site is called earthquakedamagemap.com. It is my university project. Any help would be much appreciated.
I think it is the 'value.replace' attribute which needs changing?
function changeMap2() {
var searchString = document.getElementById('search-string2').value.replace(/'/g, "\\'");
if(!searchString) {
layer.setQuery("SELECT 'Latitude' FROM " + tableid);
return;
}
layer.setQuery("SELECT 'Latitude' FROM " + tableid + " WHERE 'Updated Risk Assessment:' = '" + searchString + "'");
}
I posted some example code:
in this post not too long ago. You need to combine your search conditions with AND and call layer.setQuery with multiple search conditions only once. I don't think it has anything to do with your replace call as I didn't see any embedded single quotes in your input values.
Eric
Related
I need to search those elements who have space " " in their attributes.
For example:
<unit href="http:xxxx/unit/2 ">
Suppose above code have space in the last for href attribute.
I have done this using FLOWER query. But I need this to be done using CTS functions. Please suggest.
For FLOWER query I have tried this:
let $x := (
for $d in doc()
order by $d//id
return
for $attribute in data($d//#href)
return
if (fn:contains($attribute," ")) then
<td>{(concat( "id = " , $d//id) ,", data =", $attribute)}</td>
else ()
)
return <tr>{$x}</tr>
This is working fine.
For CTS I have tried
let $query :=
cts:element-attribute-value-query(xs:QName("methodology"),
xs:QName("href"),
xs:string(" "),
"wildcarded")
let $search := cts:search(doc(), $query)
return fn:count($search)
Your query is looking for " " to be the entirety of the value of the attribute. If you want to look for attributes that contain a space, then you need to use wildcards. However, since there is no indexing of whitespace except for exact value queries (which are by definition not wildcarded), you are not going to get a lot of index support for that query, so you'll need to run this as a filtered search (which you have in your code above) with a lot of false positives.
You may be better off creating a string range index on the attribute and doing value-match on that.
So I am using the following in the onValueEdit field of an entry form
var widgets = widget.root.descendants;
var to = 'xxxx#yyy.com';
var subject = 'Delivery Date Change For: ' + widgets.ProjectName.value;
var msg = "The Delivery Date for [ " + widgets.UsersPosition.value + " ] on [ " + widgets.ProjectName.value + " ] has been changed;
sendMessage(to, subject, msg);
So when a user changes a Delivery Date (by adjusting a Date Box) a notification email is sent out. I would like to add the actual in the Date Box but when I add " + widgets.DeliveryDate.value + " it says it is unrecognized.
Since the DeliveryDate is a Date Box, do I need something different? widgets.DeliveryDate.???
Thank you for any help.
"value" property is the one you need. Please note that it's JavaScript Date object so in some cases you need to convert it. But code you provided looks good to me.
What do you mean by "unrecognized"? Could you provide error details?
BTW: it's better to use Server Script to generate email message.
I have a client that wants to be able to pick several things off the Silverstripe tag cloud widget.
So, using jQuery, I prepare a string containing all the selected tags which I then pass to a Silverstripe function.
if($_GET["selectedTags"]){
$selectedTagString = $_GET["selectedTags"];
$selectedTagString = substr($selectedTagString, 0, strlen($selectedTagString) -1);
$tagArray = explode("|", $selectedTagString);
$blogEntries = DataObject::get("BlogEntry")->filter(array("Tags:PartialMatch" => $tagArray));
return $blogEntries->renderWith(array("blogSearchResults"));
}
}
And it works quite well.
EXCEPT for tags that have an "&" in them, like "Otago & Southland", where the search fails and nothing is retrieved.
Looking at the generated SQL, everything seems to be fine.
SELECT DISTINCT "SiteTree_Live"."ClassName", "SiteTree_Live"."Created",
.
.
.
"BlogEntry_Live"."BlogEntryThumbnailID", "SiteTree_Live"."ID", CASE WHEN "SiteTree_Live"."ClassName" IS NOT NULL THEN "SiteTree_Live"."ClassName" ELSE 'SiteTree' END AS "RecordClassName" FROM "SiteTree_Live" LEFT JOIN "Page_Live" ON "Page_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "BlogEntry_Live" ON "BlogEntry_Live"."ID" = "SiteTree_Live"."ID" WHERE ("BlogEntry_Live"."Tags" LIKE '%southland & otago championships%') AND ("SiteTree_Live"."ClassName" IN ('BlogEntry')) ORDER BY "SiteTree_Live"."Sort" ASC
Has anyone had this problem before?
Are the tags stored using & in the db? Then you first should html encode your string.
I am trying to pull information for items to display on the page. For some reason, the Master Category (masCat.cat_name) is not returning data. Here is the code for my SQL statement:
strSQL.CommandText = "Select Top 25 tblItem.item_id, tblItem.item_title
, masCat.cat_name, regCat.cat_name, tblItem.item_lot, tblCosigner.cs_txt_id
, tblItem.item_status, tblItem.item_photo_status, tblItem.item_pr
, tblItem.item_premium
From tblItem
Left Join tblCosigner On (tblItem.item_cs_txt_id = tblCosigner.cs_txt_id)
Left Join tblCDR On (tblItem.item_cdr_txt_id = tblCDR.cs_id)
Left Join tblCat As masCat On (tblItem.item_mcat_id = masCat.cat_id)
Left Join tblCat As regCat On (tblItem.item_cat_id = regCat.cat_id)
Where " + sqlQuery + "
Order By tblItem.item_id;";
try
{
conn.Open();
using (SqlDataReader itemReader = strSQL.ExecuteReader())
{
while (itemReader.Read())
{
resultText += "<tr>\n<td>" + itemReader.GetValue(0).ToString() + "</td>\n";
resultText += "<td>" + itemReader.GetValue(1).ToString() + "</td>\n";
resultText += "<td>" + itemReader.GetValue(2).ToString() + "</td>\n";
resultText += "<td>" + itemReader.GetValue(3).ToString() + "</td>\n";
resultText += "<td>" + itemReader.GetValue(4).ToString() + "</td>\n";
resultText += "<td>" + itemReader.GetValue(5).ToString() + "</td>\n";
resultText += "<td>" + itemReader.GetValue(6).ToString() + "</td>\n";
resultText += "<td>" + itemReader.GetValue(7).ToString() + "</td>\n";
if (itemReader.GetValue(8).ToString().Length > 0)
{
price = double.Parse(itemReader.GetValue(8).ToString());
}
if (itemReader.GetValue(9).ToString().Length > 0)
{
premium = double.Parse(itemReader.GetValue(9).ToString());
}
total = price + premium;
resultText += "<td>" + total.ToString("0.00") + "</td>\n</tr>\n";
}
itemReader.Close();
}
}
I was thinking that my join statement was incorrect for the masCat join, but if I just change tblItem.item_mcat_id to just tblItem.item_cat_id (which is the secondary category, also selected in this same query), it works just fine. Both are being pulled from the exact same table, but by different associated fields in the relational table. I am positive tblItem.item_mcat_id is the correct name of the field for the master category id.
Now I am used to using MySQL, and I do know that with SQL you are supposed to do a Group By as well. But I do not know what I would group by other than tblItem.item_id so that it does not combine rows of data. So I don't see how that would solve my issue either. Can anyone see anything wrong with this SQL statement? Everything returns fine except for the master category.
I got interrupted several times while writing this, so I kind of lost track of my thinking during it, so I hope I gave enough information. If not, just ask, and I will respond or update my question. Thanks in advance...
EDIT
It's in the comments, but the sqlQuery variable has a default value of "tblItem.item_id > 0". It works if I add other criteria to it dynamically (not including the master category still).
Also, I must not have stated something right, but I do receive results from this. I am only missing the master category field (it's returning blank for this one). The query itself is not failing.
FIXED
Whoever created the tables originally made the tblItem.item_mcat_id zero pad... -.-
Based on the description you've given, I'd have to say that these two columns:
tblItem.item_mcat_id = masCat.cat_id
Are not the same type or one contains padding where the other does not. You might have to do a cast. Finally MAKE SURE that the item.mcat_id DOES ACTUALLY exist in the cat_id column.
With the code you posted it is impossible to help you directly.
For starters, you need to use Parametrized Queries otherwise you're wise open for SQL Injection attacks and other nastiness.
I suggest you read Give me parametrized queries or give me death for a overview of why.
That being said, the only way to solve your problem is for you to place the full resulting query string into SQL Management Studio (or use its basic version in VS) and see what the output is. This means you'll need to output the CommandText property while executing the program.
This can be done with Debug.WriteLine(). The results will end up in your OUTPUT window by default.
A couple of things... Does not seem that you are checking to see if sqlQuery is empty string or not. Also I usually check to see if my data reader has rows before trying to read from it
if(itemReader.HasRows)
{
While(itemReader.Read())
{
}
}
not sure if those are the problems or not but I would start there.
im really new to linq-to-SQL so this may sound like a really dumb question, i have the following code
var query = from p in DC.General
where p.GeneralID == Int32.Parse(row.Cells[1].Text)
select new
{
p.Comment,
};
how do i got about getting the result from this query to show in a text box ??
That would be:
TextBox1.Text = query.Single().Comment;
You have to filter the first result from your query. To do that, you can use Single() if you know the query only returns one value. You could also use First(), if the results might contain more than one row.
Also, if it's only a single value, you could rewrite the code to:
var query = from p in DC.General
where p.GeneralID == Int32.Parse(row.Cells[1].Text)
select p.Comment;
TextBox1.Text = query.Single();