sql - Multiple database requests with one php function -
i have website in pretty regularly referencing mysql database...
in couple instances have 1 large block of php code need applied multiple database requests.
i have tried:
$result1 = $db->query($sql1); $result2 = $db->query($sql2); function action() { ...code... } foreach($result1 $row) { action(); } foreach($result2 $row) { action(); }
with code action()
function execute; however, sql request not applied code.
i tried placing $row
variable inside action function - action($row)
- did not work either.
an answer problem great in helping me conserve time , code while progressing further project.
of course , $row
variable doesn't exist in function. need pass parameter.
function action($row) { ...code... //do $row } foreach($result1 $row) { action($row); } foreach($result2 $row) { action($row); }
Comments
Post a Comment