PHP Oracle inserting data on loop got incorrect id











up vote
0
down vote

favorite












I'm continuing my previous question.



Now I need to insert the value to DB. But ID inserted is not correct as on my database master.



$qModel = oci_parse($c1, "SELECT MODELID, MODEL_NAME FROM WA_LFO_TBL_MODEL 
WHERE ACTIVE = 'Y'");
oci_execute($qModel);
while($dModel = oci_fetch_array($qModel))
{
$qDtl2 = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_MODEL_CONFIGURATION WHERE MODELID_FK = '" . $dModel['MODELID'] . "'");
oci_execute($qDtl2);
while($dDtl2 = oci_fetch_array($qDtl2))
{
$q = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_REJECT_PROCESS WHERE MODELID_FK = '" . $dModel['MODELID'] . "' ORDER BY SORT_NO ASC");
oci_execute($q);
while($d = oci_fetch_array($q))
{
$idkeys = $d['RP_ID'];
$keys = $d['RP_NAME'];
}

$values = array_fill(0, count($keys), 0);
$values = array_combine($keys, $values);

for($i = $readRowAfter; $i < count($linesReject); $i++)
{
// if the fileReject is "Tue, Sep 18<tab>2018<tab>23:59:53<tab>"
$dateobjReject = DateTime::createFromFormat($createFromFormat, $linesReject[$i]);

// check if date is in your Timespan
if($dateobjReject < $toDateTime && $dateobjReject > $fromDateTime)
{
$rowsintimespanReject++; // count if in timespan

$lineContent = explode("t", $linesReject[$i]);

// loop through line elements and count them
$x = 0;
for ($j = 0; $j < count($keys); $j++) {
if (!isset($lineContent[$j])) {
continue;
}

// remember position of last not empty column
if (trim($lineContent[$j]) != '') {
$x = $j;
}
}

if ($x > 0) {
$values[$keys[$x]]++;
}
}
}

$i = 0;
$sql = "";

foreach ($values as $value)
{
if($value != 0)
{
$sql = oci_parse($c1,"INSERT INTO WA_LFO_TBL_REJECT_OUTPUT(MODELID_FK, QUANTITY, RPID_FK, CONFIGURATIONID_FK)VALUES('" . $dModel['MODELID'] . "', '" . $value . "', '" . $idkeys[$i] . "', '" . $dDtl2['CONFIGURATIONID'] . "')");
oci_execute($sql);
}

$i++;
}
}
}


As you can see that I'm trying to insert the date on foreach function.



But inserted data for ID is not correct for RPID_FK.
I realize maybe something wrong with the code, tried to get the solution but still stuck on it.



Is something wrong on that code?










share|improve this question






















  • Iám pretty sure the modern Oracle database versions supports some kind of INSERT INTO table <columns> SELECT (<columns>) FROM table SQL syntax which also should support JOIN's so you can select from multiple tables.. What would make it alot more eazy..
    – Raymond Nijland
    Nov 12 at 10:55












  • @RaymondNijland let me know the example please
    – HiDayurie Dave
    Nov 12 at 11:18















up vote
0
down vote

favorite












I'm continuing my previous question.



Now I need to insert the value to DB. But ID inserted is not correct as on my database master.



$qModel = oci_parse($c1, "SELECT MODELID, MODEL_NAME FROM WA_LFO_TBL_MODEL 
WHERE ACTIVE = 'Y'");
oci_execute($qModel);
while($dModel = oci_fetch_array($qModel))
{
$qDtl2 = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_MODEL_CONFIGURATION WHERE MODELID_FK = '" . $dModel['MODELID'] . "'");
oci_execute($qDtl2);
while($dDtl2 = oci_fetch_array($qDtl2))
{
$q = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_REJECT_PROCESS WHERE MODELID_FK = '" . $dModel['MODELID'] . "' ORDER BY SORT_NO ASC");
oci_execute($q);
while($d = oci_fetch_array($q))
{
$idkeys = $d['RP_ID'];
$keys = $d['RP_NAME'];
}

$values = array_fill(0, count($keys), 0);
$values = array_combine($keys, $values);

for($i = $readRowAfter; $i < count($linesReject); $i++)
{
// if the fileReject is "Tue, Sep 18<tab>2018<tab>23:59:53<tab>"
$dateobjReject = DateTime::createFromFormat($createFromFormat, $linesReject[$i]);

// check if date is in your Timespan
if($dateobjReject < $toDateTime && $dateobjReject > $fromDateTime)
{
$rowsintimespanReject++; // count if in timespan

$lineContent = explode("t", $linesReject[$i]);

// loop through line elements and count them
$x = 0;
for ($j = 0; $j < count($keys); $j++) {
if (!isset($lineContent[$j])) {
continue;
}

// remember position of last not empty column
if (trim($lineContent[$j]) != '') {
$x = $j;
}
}

if ($x > 0) {
$values[$keys[$x]]++;
}
}
}

$i = 0;
$sql = "";

foreach ($values as $value)
{
if($value != 0)
{
$sql = oci_parse($c1,"INSERT INTO WA_LFO_TBL_REJECT_OUTPUT(MODELID_FK, QUANTITY, RPID_FK, CONFIGURATIONID_FK)VALUES('" . $dModel['MODELID'] . "', '" . $value . "', '" . $idkeys[$i] . "', '" . $dDtl2['CONFIGURATIONID'] . "')");
oci_execute($sql);
}

$i++;
}
}
}


As you can see that I'm trying to insert the date on foreach function.



But inserted data for ID is not correct for RPID_FK.
I realize maybe something wrong with the code, tried to get the solution but still stuck on it.



Is something wrong on that code?










share|improve this question






















  • Iám pretty sure the modern Oracle database versions supports some kind of INSERT INTO table <columns> SELECT (<columns>) FROM table SQL syntax which also should support JOIN's so you can select from multiple tables.. What would make it alot more eazy..
    – Raymond Nijland
    Nov 12 at 10:55












  • @RaymondNijland let me know the example please
    – HiDayurie Dave
    Nov 12 at 11:18













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm continuing my previous question.



Now I need to insert the value to DB. But ID inserted is not correct as on my database master.



$qModel = oci_parse($c1, "SELECT MODELID, MODEL_NAME FROM WA_LFO_TBL_MODEL 
WHERE ACTIVE = 'Y'");
oci_execute($qModel);
while($dModel = oci_fetch_array($qModel))
{
$qDtl2 = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_MODEL_CONFIGURATION WHERE MODELID_FK = '" . $dModel['MODELID'] . "'");
oci_execute($qDtl2);
while($dDtl2 = oci_fetch_array($qDtl2))
{
$q = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_REJECT_PROCESS WHERE MODELID_FK = '" . $dModel['MODELID'] . "' ORDER BY SORT_NO ASC");
oci_execute($q);
while($d = oci_fetch_array($q))
{
$idkeys = $d['RP_ID'];
$keys = $d['RP_NAME'];
}

$values = array_fill(0, count($keys), 0);
$values = array_combine($keys, $values);

for($i = $readRowAfter; $i < count($linesReject); $i++)
{
// if the fileReject is "Tue, Sep 18<tab>2018<tab>23:59:53<tab>"
$dateobjReject = DateTime::createFromFormat($createFromFormat, $linesReject[$i]);

// check if date is in your Timespan
if($dateobjReject < $toDateTime && $dateobjReject > $fromDateTime)
{
$rowsintimespanReject++; // count if in timespan

$lineContent = explode("t", $linesReject[$i]);

// loop through line elements and count them
$x = 0;
for ($j = 0; $j < count($keys); $j++) {
if (!isset($lineContent[$j])) {
continue;
}

// remember position of last not empty column
if (trim($lineContent[$j]) != '') {
$x = $j;
}
}

if ($x > 0) {
$values[$keys[$x]]++;
}
}
}

$i = 0;
$sql = "";

foreach ($values as $value)
{
if($value != 0)
{
$sql = oci_parse($c1,"INSERT INTO WA_LFO_TBL_REJECT_OUTPUT(MODELID_FK, QUANTITY, RPID_FK, CONFIGURATIONID_FK)VALUES('" . $dModel['MODELID'] . "', '" . $value . "', '" . $idkeys[$i] . "', '" . $dDtl2['CONFIGURATIONID'] . "')");
oci_execute($sql);
}

$i++;
}
}
}


As you can see that I'm trying to insert the date on foreach function.



But inserted data for ID is not correct for RPID_FK.
I realize maybe something wrong with the code, tried to get the solution but still stuck on it.



Is something wrong on that code?










share|improve this question













I'm continuing my previous question.



Now I need to insert the value to DB. But ID inserted is not correct as on my database master.



$qModel = oci_parse($c1, "SELECT MODELID, MODEL_NAME FROM WA_LFO_TBL_MODEL 
WHERE ACTIVE = 'Y'");
oci_execute($qModel);
while($dModel = oci_fetch_array($qModel))
{
$qDtl2 = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_MODEL_CONFIGURATION WHERE MODELID_FK = '" . $dModel['MODELID'] . "'");
oci_execute($qDtl2);
while($dDtl2 = oci_fetch_array($qDtl2))
{
$q = oci_parse($c1, "SELECT * FROM WA_LFO_TBL_REJECT_PROCESS WHERE MODELID_FK = '" . $dModel['MODELID'] . "' ORDER BY SORT_NO ASC");
oci_execute($q);
while($d = oci_fetch_array($q))
{
$idkeys = $d['RP_ID'];
$keys = $d['RP_NAME'];
}

$values = array_fill(0, count($keys), 0);
$values = array_combine($keys, $values);

for($i = $readRowAfter; $i < count($linesReject); $i++)
{
// if the fileReject is "Tue, Sep 18<tab>2018<tab>23:59:53<tab>"
$dateobjReject = DateTime::createFromFormat($createFromFormat, $linesReject[$i]);

// check if date is in your Timespan
if($dateobjReject < $toDateTime && $dateobjReject > $fromDateTime)
{
$rowsintimespanReject++; // count if in timespan

$lineContent = explode("t", $linesReject[$i]);

// loop through line elements and count them
$x = 0;
for ($j = 0; $j < count($keys); $j++) {
if (!isset($lineContent[$j])) {
continue;
}

// remember position of last not empty column
if (trim($lineContent[$j]) != '') {
$x = $j;
}
}

if ($x > 0) {
$values[$keys[$x]]++;
}
}
}

$i = 0;
$sql = "";

foreach ($values as $value)
{
if($value != 0)
{
$sql = oci_parse($c1,"INSERT INTO WA_LFO_TBL_REJECT_OUTPUT(MODELID_FK, QUANTITY, RPID_FK, CONFIGURATIONID_FK)VALUES('" . $dModel['MODELID'] . "', '" . $value . "', '" . $idkeys[$i] . "', '" . $dDtl2['CONFIGURATIONID'] . "')");
oci_execute($sql);
}

$i++;
}
}
}


As you can see that I'm trying to insert the date on foreach function.



But inserted data for ID is not correct for RPID_FK.
I realize maybe something wrong with the code, tried to get the solution but still stuck on it.



Is something wrong on that code?







php oracle loops






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 10:50









HiDayurie Dave

6981723




6981723












  • Iám pretty sure the modern Oracle database versions supports some kind of INSERT INTO table <columns> SELECT (<columns>) FROM table SQL syntax which also should support JOIN's so you can select from multiple tables.. What would make it alot more eazy..
    – Raymond Nijland
    Nov 12 at 10:55












  • @RaymondNijland let me know the example please
    – HiDayurie Dave
    Nov 12 at 11:18


















  • Iám pretty sure the modern Oracle database versions supports some kind of INSERT INTO table <columns> SELECT (<columns>) FROM table SQL syntax which also should support JOIN's so you can select from multiple tables.. What would make it alot more eazy..
    – Raymond Nijland
    Nov 12 at 10:55












  • @RaymondNijland let me know the example please
    – HiDayurie Dave
    Nov 12 at 11:18
















Iám pretty sure the modern Oracle database versions supports some kind of INSERT INTO table <columns> SELECT (<columns>) FROM table SQL syntax which also should support JOIN's so you can select from multiple tables.. What would make it alot more eazy..
– Raymond Nijland
Nov 12 at 10:55






Iám pretty sure the modern Oracle database versions supports some kind of INSERT INTO table <columns> SELECT (<columns>) FROM table SQL syntax which also should support JOIN's so you can select from multiple tables.. What would make it alot more eazy..
– Raymond Nijland
Nov 12 at 10:55














@RaymondNijland let me know the example please
– HiDayurie Dave
Nov 12 at 11:18




@RaymondNijland let me know the example please
– HiDayurie Dave
Nov 12 at 11:18

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260580%2fphp-oracle-inserting-data-on-loop-got-incorrect-id%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260580%2fphp-oracle-inserting-data-on-loop-got-incorrect-id%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python