Drupal 8 get data from table? - drupal-8

this is my code.
$connection = Database::getConnection();
$sth = $connection->select('node_field_word_record', 'x')
->fields('x', array('field_word_record_useruuid'));
$data = $sth->execute();
$results = $data->fetchAll(\PDO::FETCH_OBJ);
print_r($results);
but $_results is empty.
table
this is error message.
Drupal\Core\Database\DatabaseExceptionWrapper:Drupal\record_json\Controller\RecordJsonController->save_words() 中的 SQLSTATE[42S02]: Base table or view not found: 1146 Table 'fire.node_field_word_record' doesn't exist: SELECT x.field_word_record_useruuid AS field_word_record_useruuid FROM {node_field_word_record} x;
place help me guys!

It was sheer stupidity on my part guys,the rong is node_field_word_record,there is missing a _,the right table name is node__field_word_record.

Related

CAD to Feature Class

import arcpy
fc = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\789-AS-BUILT 8-7-13.dwg\Polyline'
out_gdb = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\RandolphPoint.gdb.gdb'
field = 'Layer'
values = [row[0] for row in arcpy.da.SearchCursor(fc, (field))]
uniqueValues = set(Values)
for value in uniqueValues:
sql = """Layer" = '{0}'""".format(Value)
name = arcpy.ValidateTableName(value,out_gdb)
arcpy.FeatureClassToFeatureClass_conversion(fc, out_gdb, name, sql)
I am trying to convert CAD(dwg) to ArcGIS 10.2.2 Feature Classes using a file geodatase as the workspace. I was just taught this code at an ESRI conference and of course it worked beautifully for the insturtor.
My error I am getting is "NameError:name'Values' is not defined" however I did define it as values = [row[0] for row in arcpy.da.SearchCursor(fc, (field))] I have been working hours on this, it would help out my job considerably.
Python variables are case-sensitive.
You've declared values with a lower-case v, but you're referring to it on the next line with an upper-case V.
(Same with value/Value further down.
import arcpy
fc = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\789ASBUILT.dwg\Polyline'
out_gdb = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\RandolphPoint.gdb'
field = 'Layer'
value = [row[0] for row in arcpy.da.SearchCursor(fc, (field))]
uniquevalues = set(value)
for value in uniquevalues:
sql = """"Layer" = '{0}'""".format(value)
name = arcpy.ValidateTableName(value,out_gdb)
arcpy.FeatureClassToFeatureClass_conversion(fc, out_gdb, name, sql)
Here is the solution, I had an extra .gdb in the geodatabase path
my word value was values so had to take the s off
and also in my sql statement I was missing a " before the word Layer
If anyone is reading this just change the individual parameters and it works beautifully!
thanks Juffy for responding and trying to help me out
Cartogal

Setting the datasource of the child band in UltraGrid

I have an UltraGrid in my Windows Form Application and it has to have two bands. I was able to setup the Parent Band with no problem by using the code below:
Try
con.Open()
da = New SqlDataAdapter("SELECT o.OJTID, o.Surname + ', ' + o.FirstName + ' ' + o.MiddleName AS FullName, t.TotalGrade FROM tblOJTs o INNER JOIN tblTGrades t ON o.OJTID = t.OJTID", con)
da.Fill(ds, "tblOGrades")
con.Close()
Catch ex As Exception
MsgBox("Error connecting to databe.", MsgBoxStyle.Critical)
MsgBox(ex.ToString)
con.Close()
Exit Sub
End Try
UltraGrid1.DisplayLayout.ViewStyle = Infragistics.Win.UltraWinGrid.ViewStyle.MultiBand
UltraGrid1.DataSource = ds.Tables("tblOGrades")
The thing now is, I dont know how to set the datasource of the Child Band. I dont encounter such problem with UltraWebGrid because of the Hierarchical DataSource feature but I think its not available for WinForms. I know you guys will help thanks in advance :)
You need to fill another DataTable in your DataSet with the data related to the first table. After that, you should define the relation between the two datables and finally set the DataSource of the UltraWinGrid to the DataSet itself instead of the single DataTable.
For example:
con.Open()
da = New SqlDataAdapter("SELECT o.OJTID, o.Surname ....", con)
da.Fill(ds, "tblOGrades")
da = new SqlDataAdapter("SELECT .related data....", con)
da.Fill(ds, "tblRelated")
ds.Relations.Add("Grades_Relation", _
ds.Tables("tblOGrades").Columns("OJTID"), _
ds.Tables("tblRelated").Columns("relatedID"))
con.Close()
....
UltraGrid1.DataSource = ds

What's wrong with this for scraping the table and data needed?

I'm trying to scrape data for Miami Heat and their opponent from a table at http://www.scoresandodds.com/grid_20111225.html. The problem I have is that tables for NBA and NFL and other sports are all identicaly marked and all the data I get is from the NFL table. Another problem is that I would like to scrape data for the entire season and the number of different tables changes and the position of Miami changes in the table. This is the code I've been using for different tables till now;
So why is this not getting the job done? Thx for you patience; I'm a real begginer, and I've been trying to solve this problem for some days now, to no effect.
def tableSnO(htmlSnO):
gameSections = soup.findAll('div', 'gameSection')
for gameSection in gameSections:
header = gameSection.find('div', 'header')
if header.get('id') == 'nba':
rows = gameSections.findAll('tr')
def parse_string(el):
text = ''.join(el.findAll(text=True))
return text.strip()
for row in rows:
data = map(parse_string, row.findAll('td'))
return data
Lately I decided to try a different approach; if I scrape the entire page and get the index of the data in question (this is where it stops:) I could just get the next set of data from the list, since that structure of the table never changes. I could also get the opponent's team name the same way I get the htmlSnO . It feels like this is such basic stuff and it's killing me that I can't get it right.
def tableSnO(htmlSnO):
oddslist = soupSnO.find('table', {"width" : "100%", "cellspacing" : "0", "cellpadding" : "0"})
rows = oddslist.findAll('tr',)
def parse_string(el):
text = ''.join(el.findAll(text=True))
return text.strip()
for row in rows:
data = map(parse_string, row.findAll('td'))
for teamName in data:
if re.match("(.*)MIAMI HEAT(.*)", teamName):
return teamName
return data.index(teamName)
New and final answer with working code:
The section of the page you want has this:
<div class="gameSection">
<div class="header" id="nba">
This should let you get at the NBA tables:
def tableSnO(htmlSnO):
gameSections = soup.findAll('div', 'gameSection')
for gameSection in gameSections:
header = gameSection.find('div', 'header')
if header.get('id') == 'nba':
# process this gameSection
print gameSection.prettify()
As a complete example, here's the full code I used to test:
import sys
import urllib2
from bs4 import BeautifulSoup
f = urllib2.urlopen('http://www.scoresandodds.com/grid_20111225.html')
html = f.read()
soup = BeautifulSoup(html)
gameSections = soup.findAll('div', 'gameSection')
for gameSection in gameSections:
header = gameSection.find('div', 'header')
if header.get('id') == 'nba':
table = gameSection.find('table', 'data')
print table.prettify()
This prints the NBA data table.

How to get Place ID of city from Latitude/Longitude using Facebook API

I need to find the Facebook place for the city for many lat/long points. The actual points refer to personal addresses, so there are no exact place ID's to look for as in the case of a business.
For testing, I was looking for the town of Red Feather Lakes, CO.
The graph search function will return a lot of places, but does not return cities Example
Raw FQL does not let you search by lat/long, and has no concept of "nearby" anyway. Example
An FQL query by ID reveals that there is an least a "Display Subtext" field which indicates that object is a city. Example
Thanks for any help. I have over 80 years of dated and geotagged photos of my dad that he would love to see on his timeline!
EDIT
Cities are not in the place table, they are only in the page table.
There is an undocumented distance() FQL function, but it only works in the place table. (Via this SO answer.)
This works:
SELECT name,description,geometry,latitude,longitude, display_subtext
FROM place
WHERE distance(latitude, longitude, "40.801985", "-105.593719") < 50000
But this gives an error "distance is not valid in table page":
SELECT page_id,name,description,type,location
FROM page
WHERE distance(
location.latitude,location.longitude,
"40.801985", "-105.593719") < 50000
It's a glorious hack, but this code works. The trick is to make two queries. First we look for places near our point. This returns a lot of business places. We then take the city of one of these places, and use this to look in the page table for that city's page. There seems to be a standard naming conventions for cities, but different for US and non-US cities.
Some small cities have various spellings in the place table, so the code loops through the returned places until it finds a match in the page table.
$fb_token = 'YOUR_TOKEN';
// Red Feather Lakes, Colorado
$lat = '40.8078';
$long = '-105.579';
// Karlsruhe, Germany
$lat = '49.037868';
$long = '8.350124';
$states_arr = array('AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas",'CA'=>"California",'CO'=>"Colorado",'CT'=>"Connecticut",'DE'=>"Delaware",'FL'=>"Florida",'GA'=>"Georgia",'HI'=>"Hawaii",'ID'=>"Idaho",'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas",'KY'=>"Kentucky",'LA'=>"Louisiana",'ME'=>"Maine",'MD'=>"Maryland", 'MA'=>"Massachusetts",'MI'=>"Michigan",'MN'=>"Minnesota",'MS'=>"Mississippi",'MO'=>"Missouri",'MT'=>"Montana",'NE'=>"Nebraska",'NV'=>"Nevada",'NH'=>"New Hampshire",'NJ'=>"New Jersey",'NM'=>"New Mexico",'NY'=>"New York",'NC'=>"North Carolina",'ND'=>"North Dakota",'OH'=>"Ohio",'OK'=>"Oklahoma", 'OR'=>"Oregon",'PA'=>"Pennsylvania",'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'DC'=>"Washington D.C.",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming");
$place_search = json_decode(file_get_contents('https://graph.facebook.com/search?type=place&center=' . $lat . ',' . $long . '&distance=10000&access_token=' . $fb_token));
foreach($place_search->data as $result) {
if ($result->location->city) {
$city = $result->location->city;
$state = $result->location->state;
$country = $result->location->country;
if ($country=='United States') {
$city_name = $city . ', ' . $states_arr[$state]; // e.g. 'Chicago, Illinois'
}
else {
$city_name = $city . ', ' . $country; // e.g. 'Rome, Italy'
}
$fql = 'SELECT name,page_id,name,description,type,location FROM page WHERE type="CITY" and name="' .$city_name. '"';
$result = json_decode(file_get_contents('https://graph.facebook.com/fql?q=' . rawurlencode($fql) . '&access_token=' . $fb_token));
if (count($result->data)>0) {
// We found it!
print_r($result);
break;
}
else {
// No luck, try the next place
print ("Couldn't find " . $city_name . "\n");
}
}
}
I found this solution worked for me when looking for a page for the closest city to the specified latitude/longitude. For some reason LIMIT 1 didn't return the closest city so I bumped up the limit and then took the first result.
SELECT page_id
FROM place
WHERE is_city and distance(latitude, longitude, "<latitude>", "<longitude>") < 100000
ORDER BY distance(latitude, longitude, "<latitude>", "<longitude>")
LIMIT 20

multiple if's for calculated field in tableau

please pardon the absolutely newbie question but i'm very new to tableau.
what I'd like to do is create a message based on which filter flags are active. so, in psuedo code, i'd do something like this:
message = ''
if filter1 == 1:
message += 'filter 1 is active'
if filter2 == 1:
message += ' filter 2 is active'
return message
problem is, I'm not even sure how to do multiple if statements - i keep getting a syntax error. Any help will be greatly appreciated.
Here is an example of how I accomplished something similar:
IF [ZAVUFA1_FED_COLL_CHOICE_1] = 'xxxxx' THEN 1
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_2] = 'xxxxx' THEN 2
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_3] = 'xxxxx' THEN 3
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_4] = 'xxxxx' THEN 4
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_5] = 'xxxxxx' THEN 5
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_6] = 'xxxxx' THEN 6
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_7] = 'xxxxxx' THEN 7
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_8] = 'xxxxxx' THEN 8
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_9] = 'xxxxx' THEN 9
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_10] = 'xxxxxx' THEN 10
ELSEIF ISNULL([ZAVUFA1_FED_COLL_CHOICE_1]) THEN 99
END
As much as I love stackoverflow, Tableau also has a great user forum on their site.
You would create a calculated field called message with this code:
IF filter1 = 1 THEN 'filter 1 is active' END
+ IF filter2 = 1 THEN ' filter 2 is active' END
what I ended up doing is creating a calculated field for each if statement. I then created yet another calculated field that concatenates all of the output from each of the first set of calculated fields I created. Seems like a bit of a hack so If anyone knows of a more elegant way of doing this (making a calculated field of a series of calulated fields seems awfully kludgy) I'd be glad to pass on the points for answering.