Having a hard time figuring this, how to display "name" using only like 3 letter string. example below.
$query = oci_parse($conn, "SELECT * FROM STAFF_DETAILS WHERE NAME = '$name' ");
if(oci_execute($query))
{
while(($row = oci_fetch_array($query, OCI_BOTH)) != false)
{
echo $row['NAME'];
}
}
the problem is you can display only the fullname (ex. Zach De La Rocha), what i want is to display all names begins "Zach" only.
Thanks
Not sure I understand your question, it would help if you could be a little clearer. Just guessing, if you are asking how you can select only the records where the name begins with 'Zach', the Oracle syntax is:
...where name like 'Zach%'
The % in the expression above means "anything may come after Zach". Since there is no % before Zach, that means Zach must be at the beginning of name.
Related
I have created internal tables where I want to update age of employee in one internal table by calculating it from another table, I have done arithmetic calculations to get age but now how can I update it by any alternate way instead of MODIFY?
WRITE : / 'FirstName','LastName', ' Age'.
LOOP AT gt_items1 INTO gwa_items1.
READ TABLE gt_header INTO gwa_header WITH KEY empid = gwa_items1-empid.
gwa_items1-age = gv_date+0(4) - gwa_header-bdate+0(4).
MODIFY gt_items1 from gwa_items1 TRANSPORTING age WHERE empid = gwa_items1-empid.
WRITE : / gwa_items1-fname , gwa_items1-lname , gwa_items1-age .
ENDLOOP.
Use field symbols (instead of work areas) by LOOPing over internal tables:
WRITE : / 'FirstName','LastName', ' Age'.
LOOP AT gt_items1
ASSIGNING FIELD-SYMBOL(<ls_item1>).
READ TABLE gt_header
ASSIGNING FIELD-SYMBOL(<ls_header>)
WITH KEY empid = <ls_item1>-empid.
IF sy-subrc EQ 0.
<ls_item1>-age = gv_date+0(4) - <ls_header>-bdate+0(4).
WRITE : / <ls_item1>-fname , <ls_item1>-lname , <ls_item1>-age .
ENDIF.
ENDLOOP.
Field symbols have two advantages:
They modify the internal table directly, no separate MODIFY is
necessary.
They are somewhat faster, than work areas.
Besides József Szikszai's answer you could also use references:
write : / 'FirstName','LastName', ' Age'.
sort gt_header by empid. " <------------- Sort for binary search
loop at gt_items1 reference into data(r_item1).
read table gt_header reference into data(r_header)
with key empid = r_item1->empid binary search. " <------------- Faster read
check sy-subrc eq 0.
r_item1->age = gv_date+0(4) - r_header->bdate+0(4).
write : / r_item1->fname , r_item1->lname , r_item1->age .
endloop.
I added some enhacements to your code also.
For more info check this link.
Here is my data set.
Data in
I'd like to check if the gender with "Potential Original" matched the gender with "Potential Duplicate'. There is no specified group but 1 duplicate + 1 or more original acted like a group.
Here is the output I want (for duplicate it's NA because it's comparing to itself).
Data out
Appreciate your help. Thanks.
Thanks Rahul for looking into this. This is what I tried and I think it worked. The logic is to create the seq # first for each block of Duplicate and Original and then pull the lag value with corresponding distance.
library(data.table)
setDT(df)[, counter := seq_len(.N), by = list(cumsum(Status == "Potential
Duplicate"))]
for (i in 1:nrow(df)) {
if (df$Status[i]=="Potential Duplicate") {
df$Gender_LAG[i] <-df2$Gender[i]
}
else {
df$Gender_LAG[i]<-df2$Gender[i-df2$counter[i]+1]
}
}
Thanks.
Looking forwards to seeing other options.
In student123__C detail page there are 3 fields: firstname__c. lastname__c, middlename__c. I need to write a trigger to check "if a person is entering the same values then, throw an error that "duplicate contact found".
Example: 1st record I entered as " Siva Naga Raju " so if am again entering this same name then it should throw an error.
For that i created a forumla field called TOTALNAME__C ( firstname__c + lastname__c + middlename__c). upto here ok. But trigger not firing, intially i worte bulk trigger, but its not firing, so i wrote a simple trigger then, it is also not firing, please some boby help me. thanks in advance.
trigger duplicatefullname on student123__c (before insert, before update) {
string name;
list<student123__c> databasenames;
for (student123__c stu : trigger.new) {
name = stu.firstname__c + stu.lastname__c + stu.middlename__c;
databasenames = [select totalname__C from student123__c where totalname__C = :name];
if (databasenames.size() > 0)
stu.adderror('another person with duplicate full name found');
}
}
Basically, formula doesn't store any value. Formula is executed only when you retrieve it.
A formula is similar to an equation that is executed at run time.
I'm trying to develop a blog using webpy.
def getThread(self,num):
myvar = dict(numero=num)
print myvar
que = self.datab.select('contenidos',vars=myvar,what='contentTitle,content,update',where="category LIKE %%s%" %numero)
return que
I've used some of the tips you answer in this web but I only get a
<type 'exceptions.NameError'> at /
global name 'numero' is not defined
Python C:\xampp\htdocs\webpy\functions.py in getThread, line 42
Web GET http://:8080/
...
I'm trying to make a selection of some categorized posts. There is a table with category name and id. There is a column in the content table which takes a string which will be formatted '1,2,3,5'.
Then the way I think I can select the correct entries with the LIKE statement and some %something% magic. But I have this problem.
I call the code from the .py file which builds the web, the import statement works properly
getThread is defined inside this class:
class categoria(object):
def __init__(self,datab,nombre):
self.nombre = nombre
self.datab = datab
self.n = str(self.getCat()) #making the integer to be a string
self.thread = self.getThread(self.n)
return self.thread
def getCat(self):
'''
returns the id of the categorie (integer)
'''
return self.datab.select('categorias',what='catId', where='catName = %r' %(self.nombre), limit=1)
Please check the correct syntax for db.select (http://webpy.org/cookbook/select), you should not format query with "%" because it makes code vulnerable to sql injections. Instead, put vars in dict and refer to them with $ in your query.
myvars = dict(category=1)
db.select('contenidos', what='contentTitle,content,`update`', where="category LIKE '%'+$category+'%'", vars=myvars)
Will produce this query:
SELECT contentTitle,content,`update` FROM contenidos WHERE category LIKE '%'+1+'%'
Note that I backquoted update because it is reserved word in SQL.
I have written a code in php to connect and insert into a MSSQL database. i don't know much in php because am new to this. i used odbc to connect database.user can enter his details through the form. after submitting the form the details are getting stored into a database.
while inserting rows into a database am not trying to insert duplicate values . for this i have given if conditions.these conditions are able to notice the user cname and name exist in the database if the same name exist. but the else part after these conditions not working i.e rows are not getting inserted. i put everything inside the while loop. how can i correct it?
this is my code written in php
$connect = odbc_connect('ServerDB','sa', 'pwd');//connects database
$query2="select count(*) from company";//this is needer for loop through
$result2=odbc_exec($connect,$query2);
while(odbc_fetch_row($result2));
{
$count=odbc_result($result2,1);
echo "</br>","$count";
}
$query1="select * from company";
$result1 = odbc_exec($connect, $query1);
# fetch the data from the database
$index=0;
while(odbc_fetch_row($result1))
{
$compar[$count] = odbc_result($result1, 1);
$namearray[$count] = odbc_result($result1, 2);
if($compar[$count]==$_POST['cname'])
{
echo "<script> alert(\"cname Exists\") </script>";
}
else if($namearray[$count]==$_POST['name'])
{
echo "<script> alert(\"Name Exists\") </script>";
}
else {
$query=("INSERT INTO company(cname,name) VALUES ('$_POST[cname]','$_POST[name]') ");
$result = odbc_exec($connect, $query);
echo "<script> alert(\"Row Inserted\") </script>";
} }
You generally don't allocate memory in PHP. The PHP interpreter handles it for you. Just go ahead and assign elements to your array and all the memory allocation is taken care of for you.
$index = 0;
Then you do $index++ until the last index is reached.
So index further on stays e.g. 12
So anywhere you can only access the index [12]
In PHP arrays are implemented as what would be a HashMap in Java. It will be sized automatically depending on what you put into it, and there is no way you can give an initial capacity.