[php+mysql] how to get the inserted record ID?
Hi all,
I have a standard php page that inserts a record in a mysql
db.
is there a way to save the record ID on a session variable
just after
storing the new record on the db? I would like to be able to
get this
record ID on a specific page where I would allow the user to
print
this specific record, by filtering the db by this session
variable.
I can use MX Kollection (last version, not PRO).
TIA
tony
>...
>mysql_query(...);
>$_SESSION['lastId'] = mysql_insert_id();
>HTH
>Micha
Hi Micha,
I think that it a bit more complicated.
I can't find any occurrence of that mysql call.
I used MX Kollection INSERT FORM function.
here is the code (partially):
===============================
<? // Load the common classes
require_once('../includes/common/KT_common.php');
// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');
// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");
// Make unified connection variable
$conn_test_conn = new KT_connection($tes_conn,
$database_test_conn);
// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger
// Make an insert transaction instance
$ins_rl_test = new tNG_insert($conn_test_conn);
$tNGs->addTransaction($ins_rl_test);
// Register triggers
$ins_rl_test->registerTrigger("STARTER",
"Trigger_Default_Starter", 1,
"POST", "KT_Insert1");
$ins_rl_test->registerTrigger("BEFORE",
"Trigger_Default_FormValidation", 10, $formValidation);
$ins_rl_test->registerTrigger("END",
"Trigger_Default_Redirect", 99,
"2.php?idp1={id_rl}");
// Add columns
$ins_rl_test->setTable("rl_test");
$ins_rl_test->addColumn("nome_rl", "STRING_TYPE", "POST",
"nome_rl");
$ins_rl_test->addColumn("cognome_rl", "STRING_TYPE",
"POST",
"cognome_rl");
$ins_rl_test->addColumn("datanascita_rl", "DATE_TYPE",
"POST",
"datanascita_rl");
$ins_rl_test->addColumn("cancellato_rl", "STRING_TYPE",
"POST",
"cancellato_rl");
$ins_rl_test->addColumn("cancellato_data_rl", "DATE_TYPE",
"POST",
"cancellato_data_rl");
$ins_rl_test->setPrimaryKey("id_rl", "NUMERIC_TYPE");
// Execute all the registered transactions
$tNGs->executeTransactions();
// Get the transaction recordset
$rsrl_test = $tNGs->getRecordset("rl_test");
$row_rsrl_test = mysql_fetch_assoc($rsrl_test);
$totalRows_rsrl_test = mysql_num_rows($rsrl_test);
?>
===========================
as you can see, all data is processed by other functions in
other
included files.... :(.
I think I need to better understand the TNG engine and try to
create a
little trigger that creates a session variable just after
inserting
the record in the db.
I already tried to do so, honestly, but with really poor
results.
Ciao Micha. ;).
tony
Similar Messages
-
How to get the previous record value in the current record plz help me...
In my sql how to get the previous record value...
in table i m having the field called Date i want find the difference b/w 2nd record date value with first record date... plz any one help me to know this i m waiting for ur reply....
Thanx in Advance
with regards
kotreshFirst of this not hte mysql or database forum so don;t repeate again.
to get diff between two date in mysql use date_format() to convert them to date if they r not date type
then use - (minus)to get diff. -
How to get the individual records
Table A
SNO DAY_FROM DAY_TO
1 1 3
Result:
DAY_FROM DAY_TO
1 3
2 3
3 3
Above mentioned Table DAY_TO value is 3 ,
So in that How to get the 3 individual records for above mentioned row.
Thanks in advance.
Edited by: UserK on Sep 11, 2009 8:14 AM1 with t as
2 ( select 1 day_from, 3 day_to from dual)
3 select day_from +level -1 day_from, day_to
4 from t
5* connect by level <= day_to
SQL>
SQL>/
DAY_FROM DAY_TO
1 3
2 3
3 3 -
how to get the record with the max sequence no
table as
seq student mark
1 A 10
2 A 15
1 B 20
2 B 10
1 C 30
here is what i need
seq student mark
2 A 15
2 B 10
1 C 30i have used your query + some decode
With t As
Select 'A' st, 'X' Type, 1 seq, 001 marker_no, 10 mark From dual Union All
Select 'A', 'X', 2, 001, 12 From dual Union All
Select 'B', 'X', 1, 002, 10 From dual Union All
Select 'B', 'X', 2, 003, 12 From dual Union All
Select 'B', 'X', 3, 003, 15 From dual Union All
Select 'C', 'X', 1, 001, 10 From dual Union All
Select 'C', 'X', 2, 002, 15 From dual Union All
Select 'C', 'Y', 3, 001, 20 From dual Union All
Select 'C', 'Y', 4, 001, 10 From dual
Select st,
Sum (x_cnt) x_cnt,
Max (x_seq) Keep (dense_rank Last Order By x_seq) x_seq,
max(x_marker_no) keep(dense_rank last order by x_seq) x_marker_no,
max(x_mark) keep(dense_rank last order by x_seq) x_mark,
sum(y_cnt) y_cnt,
max(y_seq) keep(dense_rank last order by y_seq) y_seq,
max(y_marker_no) keep(dense_rank last order by y_seq) y_marker_no,
max(y_mark) keep(dense_rank last order by y_seq) y_mark
from
(Select st,
decode(Type ,'X',1,0) x_cnt,
decode(type ,'X',seq,0) x_seq,
decode(Type ,'X',marker_no,0) x_marker_no,
decode(Type ,'X',mark,0) x_mark,
decode(Type ,'Y',1,0) y_cnt,
decode(Type ,'Y',seq,0) y_seq,
decode(Type ,'Y',marker_no,0) y_marker_no,
decode(Type ,'Y',mark,0) y_mark
From t
Group By st;
/*this is the output
st X_cnt X_seq X_marker_no X_mark Y_cnt Y_seq Y_marker_no Y_mark
A 2 2 001 12 0 null null null
B 3 3 003 15 0 null null null
C 2 2 002 15 2 4 001 10
ST X_CNT X_SEQ X_MARKER_NO X_MARK Y_CNT Y_SEQ Y_MARKER_NO Y_MARK
A 2 2 1 12 0 0 0 0
B 3 3 3 15 0 0 0 0
C 2 2 2 15 2 4 1 10 -
How to get the last record from the database
I am using MS Access database and Swings as GUI. I want to get the last record of a particular column from the table and store it as a varaible.
Hi
To get Last record of resultset, you have pass some parameter in constructor of CreateStatement.In such case Resultset should be scrollable and Readonly
Example
objStatement=objCon.createStatement ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
mwwResultSet=cwwStatement.executeQuery(mwwSqlQuery);
while(mwwResultSet.next())
if(mwwResultSet.isLast())
//Fetch the required column record.
String abc=mwwResultSet.getString(1);
I think this will work. Try it.
bye -
How to get the last record of an internall table ....
Hi All..
i want to get the last record of an internal table itab, and i want the the value of the last record.Hi,
Use describe statment.
data: lv_line type i.
Describe table itab lines lv_line.
read table itab into wa_itab index lv_line.
regards,
Santosh Thorat -
How to get the last record??
Hi, I now have to get only the last record from one table
from MS Access.
I was looking for the useful method from API, however,
I cannot get it.
How to get only the last record from one table ???
Please help, thanks.In RDBMS, row order is really not relavent by iteself. Meaning there is no such thing as 'last record' unless it's in the context of a column (e.g. timeStamp).
Of course, rows are inserted and stored in some natural order, but you cannot assume they'll come back the same way in a 'Select *' as they were entered.
So, if you mean last row as in last inserted row, I would add a timestamp field that's set at insert, or use a autonumber column. Either way, have a column that will always contain the highest number or newest timestamp, and then you can build your where clause from that.
For instance, in Access, I have an autonumbered field called 'fred', with other columns. If I want the last record, I simply use the following:
select * from atable where fred in (SELECT max(fred) AS Max FROM atable);
the 'where in' clause will filter to only those records in the subsequent select statment, which of course is only one, the max of the column fred.
bRi -
How to get the total record count for the report
Hi,
How can I get count of the total records shown in the report. When we set the report attributes, we have an option "Set Pagination from X to Y of Z"
Does anyone know how can I get the Z value from APEX variables.
I know we can use that query and get the count but I just want to know how we can use APEX Variables effectively.
Thanks in advance.You write a loop, something like this:
Go_block('B1');
If not form_success then
Raise Form_Trigger_failure;
End if;
First_Record;
If not form_success then
Raise Form_Trigger_failure;
End if;
Loop
If :system.record_status in('CHANGED','INSERT') then
-- modify the record here--
End if;
Exit when :System.Last_Record = 'TRUE';
Next_Record;
End Loop;
First_Record;But be very careful-- If your block can fetch a large number of rows, (over 100), this loop can take a long time, and you should not use this method. The loop will continue fetching more rows from the database until all rows satisfying the query are retrieved. -
How to get the total record count in ODI
Hi
I have the interface the are file to DB.
The format is like this..
HEADER
DETAIL
TRAILER
Now will write the contains of file to DB,
But i have to insert the total count ie numberof record written from file to DB in my Trailer record.
can you tell me how can i get the total count of records in file and write it to trailer?
Also, I want the interface to rollback the data if something fails will loading the data from file., ie. if there are 100 records in file and 50 got transfer and something fails i want to rollabck the 50 records from DB.???
Thanks :)Hi
You can design a flow for Full load flow and incremental flow from flat file to Table.
Create a table at target database like.. (create table with last_execution and palce the V_FULL_LOAD value and LAST_EXECUTION_DT columns in last_execution table)
Add faltfile as table in model, create a variable as V_FULL_LOAD and make sure that the default values is 01-01-1900
Create one more variable like V_LAST_EXECUTION_DATE (in this variable write a case statement that if V_FULL_LOAD value is 'Y" then full load should happen and same time you should check that V_FULL_LOAD column is balnk then write insert statment else write update statement to update last_execution_dt column, similar for 'N')
please provide your *personal mail ID*, i will send a doc file realted to your query.
we have to tables present in work repository (SNP_STEP and STEP_LOG tables) using tables we can get how many records are inserted/updated and we can find how many records are not transfer and gor error.
Thanks
Phani -
How to get the original record Number in Multi-Record Block
Hello Everyone,
I know how to find the duplicate item in the multi-Record block,
For Ex:
Line_Num Item_Name Quantity
1 AA 10
2 BB 20
3 AA Here 3rd record Item_name is duplicated, I can able to check and display the message that 'Item is duplicated' ,I found from [sheikyerbouti.developpez.com/duplicates/duplicates.htm] .
but I want to show along with original line number i.e 1 when the item_name is entered .
Here I want to check the original Line_Num and want to display the message
'Item is duplicated,Update quantity in Original Line 1'
Can anyone help me to get this?
Thank You.
Regards,
Guru.Hi Francois,
Actually I want to check and show the message when the item_name is entered i.e WHEN-VALIDATE-ITEM TRIGGER.
I put the following code in WHEN-VALIDATE-ITEM TRIGGER
Declare
curnum number;
dupnum number;
cur_item varchar2(100);
v_alert_no number;
p_linerec varchar2(100);
Begin
curnum := TO_NUMBER(:System.Trigger_Record);
cur_item := :Lines.Item_number;
First_Record;
p_linerec := :Lines.Item_number;
LOOP
If p_linerec = cur_item then
dupnum := :Lines.Line_num;
set_alert_property('ALERT_STOP',ALERT_MESSAGE_TEXT,
'Duplicate Item Found,Update QTY in Original line number '||dupnum);
V_ALERT_NO := show_alert('ALERT_STOP');
:LINES.ITEM_NUMBER := NULL;
:LINES.ITEM_DESCRIPTION:= NULL;
:LINES.ITEM_REVISION:= NULL;
:LINES.ITEM_CATEGORY:= NULL;
elsIF (:System.Last_Record = 'TRUE') THEN
Go_Record(curnum);
EXIT;
ELSE
Next_Record;
END IF;
END LOOP;
End; But I am getting the following error,
FRM-40737:Illegal Restricted Procedure
FIRST_RECORD in WHEN-VALIDATE-TRIGGERand then
its showing for first line itself.
Duplicate Item found.Update QTY in Original line number 1so I put the condition
If :Lines.Line_num > 1 then --Only to check when the block having more than one record.but now it checking from second record and displaying,
Duplicate Item found.Update QTY in Original line number 2 --(instead of Update QTY in Original line number 1)Can you tell me how can I change the above code for my requirement?
Thank you.
Edited by: Gurujothi on 27 Mar, 2013 5:20 PM -
How to get the Data Record Number in BI 7.0?
Hi All,
In our requirement we need to load the Data Record Number in the DSO. I got the Request ID and Data Packet Number but not the Data Record Number.
Does anyone has any idea?Hi......
When the data is activated in DSO, it is written to the table of active data, where it is then available for reporting. Requests are sorted by the key of the DataStore object, request ID, data package ID, or data record number.
You just load the data to the DSO.....and activate it.......it will autometically get generated.......You cannot load it from one DSO to other beacuse in this case Change log table is used........and this filed is in active table..........I think you need this fir reporting purpose.....so load it and activate the DSO......then it will be available in your active table for reporting.........because reporting is done on active table.......
Check this link :
http://help.sap.com/saphelp_nw04s/helpdata/en/a9/49453cabf4ef6fe10000000a114084/frameset.htm
Hope this helps you....
Regards,
Debjani....
Edited by: Debjani Mukherjee on Sep 16, 2008 5:22 PM
Edited by: Debjani Mukherjee on Sep 16, 2008 5:25 PM -
How to get the inserted row primary key with out using select statement
how to return the primary key of inserted row ,with out using select statement
Edited by: 849614 on Apr 4, 2011 6:13 AMyes thanks to all ,who helped me .its working fine
getGeneratedKeys
String hh = "INSERT INTO DIPOFFERTE (DIPOFFERTEID,AUDITUSERIDMODIFIED)VALUES(DIPOFFERTE_SEQ.nextval,?)";
String generatedColumns[] = {"DIPOFFERTEID"};
PreparedStatement preparedStatement = null;
try {
//String gen[] = {"DIPOFFERTEID"};
PreparedStatement pstmt = conn.prepareStatement(hh, generatedColumns);
pstmt.setLong(1, 1);
pstmt.executeUpdate();
ResultSet rs = pstmt.getGeneratedKeys();
rs.next();
// The generated order id
long orderId = rs.getLong(1); -
How to use the insert record and check username function?
Hi guys.
I have an error that has me stumped.
I have a form that inserts text from a text field into a
mysql database and I have added a check user name function to check
if this number already exists.
Here's the page
http://www.thechallenge.net.au/redemption2.php
The error I get when using the page on the web is this
Duplicate entry '' for key 1
Can anyone help with this?ottoman007 wrote:
I have tried the COUNTIF I input my formula =COUNTIF(6C:6M,">t") to the right of the row that I want to count and I get a red triangle and it says it isn't a valid reference. ... I am boggled how to do this.
Badunit wrote:
One parameter is the range (your row or column of checkboxes) and the other is the condition you want to count, which is TRUE.
=COUNTIF(6C:6M,TRUE)
Regards,
Barry -
How to get the total record in the block before save them
Hello,
I need to recalculate the amout for all records in one block before saving them.
How can I get it?
Thanks for your helpingYou write a loop, something like this:
Go_block('B1');
If not form_success then
Raise Form_Trigger_failure;
End if;
First_Record;
If not form_success then
Raise Form_Trigger_failure;
End if;
Loop
If :system.record_status in('CHANGED','INSERT') then
-- modify the record here--
End if;
Exit when :System.Last_Record = 'TRUE';
Next_Record;
End Loop;
First_Record;But be very careful-- If your block can fetch a large number of rows, (over 100), this loop can take a long time, and you should not use this method. The loop will continue fetching more rows from the database until all rows satisfying the query are retrieved. -
How to get the insert scripts from a table data
hi all,
i want insert scripts for 100 records from a table.
suppose i have a table xyz
xyz:
id name
1 abc
2 def
i should get insert script for 100 rows like
insert into xyz(id,name) values (1,'abc');
insert into xyz(id,name) values (2,'def');
i want 100 records data from all the tables from my database.
thanks in advance to all.SQL> create table xyz (id number, name varchar2(10));
Table created.
SQL> insert into xyz values(1,'abc');
1 row created.
SQL> insert into xyz values(2,'def');
1 row created.
SQL> select 'insert into xyz values(id,name) values('||id||','''||name||''');' from xyz;
'INSERTINTOXYZVALUES(ID,NAM
insert into xyz values(id,name) values(1,'abc');
insert into xyz values(id,name) values(2,'def');
SQL>- - - - - - - - - - - - - - - - - - - - -
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com
[Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]
Maybe you are looking for
-
This ocurred on my Dell Laptop, it seems, after several reset Firefox to Default. My Dell is an Inspriron/8600. I have removed Firefox and reloaded twice. What should Ido next. Thanks Bernard Crotty <sub>edit: removed your mail address from public di
-
Document on 10g RAC setup on solaris using vmware
Hi All, I am planning to setup "Oracle 10g RAC setup on Solaris using vmware", but I am strucked up at installation of Soaris 10 in VMWare. Can any body please help/provide me the document on Solaris 10 installation for RAC setup . The main problems
-
We are using CRM 5.0 and E-Commerce B2B. In text object CRM_ORDERI I assign new text ID's (ZD04) and text procedure (Z4) for sales item. I assign access sequence ISA_AG01 to the text ID. However text I added to documents in the E-Commerce web channel
-
My ipod froze in the middle of updating to new iOS 6
and i did the hold lock and home button thinking it will make it faster. it turned my ipod off but it didnt go to my home screen. it went to white. i held the buttons again now it went to a different color. currently the screen is green. please help.
-
My HP will begin to print, but will only print out the top couple of inches of a document. I have Windows 7 Someone told me that I need to have my settings changed on the printer. If that is true, I do not know how to do that. I hope that somebody