1
I have the following code:
$Position = $this->conn->prepare("SELECT MAX(OrderTask)+1 as OrderNew FROM tasks");
$Position->execute();
$newPosition = $Position->fetchAll(PDO::FETCH_NUM);
$newPosition = $row['OrderNew'];
$stmt = $this->conn->prepare("INSERT INTO tasks (Project, CompanyFantasy, Priorities, Delivery, Attachment, ByUser, Systems, OrderTask, Subject) VALUES
(:project, :companyfantasy, :priorities, :delivery, :attachment, :byuser, :systems, :ordertask, :subject)");
$stmt->bindparam(":project", $project);
$stmt->bindparam(":companyfantasy", $companyfantasy);
$stmt->bindParam(":priorities", $priorities);
$stmt->bindParam(":delivery", $delivery);
$stmt->bindparam(":attachment", $file_name);
$stmt->bindParam(":byuser", $byuser);
$stmt->bindParam(":systems", $systems);
$stmt->bindParam(":ordertask", $newPosition);
$stmt->bindParam(":subject", $subject);
$stmt->execute();
The $Position
: Does the SELECT
of the line OrderTask
, inside the table Tasks
, where you take the last number, add +1 and write to Ordernew.
The $newPosition
: Holds the value of $Position
.
But when I try to play the return of $newPosition
within the INSERT
this value is always 'NULL'.
Someone has an idea of how to take the value of OrderTask
and add +1?
I didn’t notice, but I did
fetchAll()
for testing, but same asfetch()
always returns zero.– Wagner Viana
@Wagnervian you are using
FETCH_ASSOC
orFETCH_NUM
? if it is the second just change$row['OrderNew']
for$row[0]
– rray
I’m using
FETCH_NUM
and have already putFETCH_ASSOC
and the two return NULL, even putting$row['OrderNew]
or$row[0]
.– Wagner Viana
@Wagnervian do
print_r($Position->fetchAll(PDO::FETCH_NUM));
and put here the result.– rray
Only
Array()
– Wagner Viana