Page 199 - PHP Novice to Ninja

Hello,
Someone can you explain this line?

$jokeId= $row['id'];

These the complete code:

//Delete joke category entries
try
{
$sql= ' DELETE FROM jokecategory WHERE jokeid= :id';
$s= $pdo->prepare($sql);

// For each joke
foreach ($result as $row)
{
$jokeId= $row['id'];
$s->bindValue(':id' , $jokeId);
$s->execute();
}
}

Thank you

It’s taking the value from a recordset and placing into a local variable. That local variable is then used as the binding value in the deletion statement executed next.

That line could have just as easily been combined with the next line, and skipped that assignment completely.

$s->bindValue(':id' , $row['id']);

Ok then I can simply use that line, or the author has assign the value for some particular reason?

Thank you

I think he used additional variable only for readability
Because

$jokeId= $row['id'];
$s->bindValue(':id' , $jokeId);

tells much more than

$s->bindValue(':id' , $row['id']);

Ok thank you

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.