I'm having some trouble with a loop in php.
The loop is something like this:
while($item = $stmt->fetch(PDO::FETCH_ASSOC)){
//Check for a special condition, the id of that item, like if($item['id'] == X)
//for each id, theres a diferente if/else if in which I make another query to get the name
$query_sql = "SELECT name from another_table where item_id = :id";
$query_stmt = $handler->prepare($query_sql);
$query_stmt->bindParam(':id',$item['id'],PDO::PARAM_INT);
$query_stmt->execute();
//fetch the result and put it into a variable
}
The problem is that the loop seems to be working only for the first record, so it is probably erroring out somewhere in the middle. I've also noticed that if I run a query to get the count of all the user items before the loop, then the loop will also fail.
Is there any limit to how many queries you can run in mssql from php?
Thank you in advance.
EDIT: I should also say that if I don't try to make a query in the middle to get the items name, then the loop will fully work.
EDIT 2:
this is the function i'm using to get the items names:
`function get_item_name($id){
$item_name = "SELECT szName from TABLE_WITH_NAME where wItemID = :id";
$item_name_stmt = $dbg->prepare($item_name);
$item_name_stmt->bindParam(':id', $id, PDO::PARAM_INT);
$item_name_stmt->execute();
$item_info = $item_name_stmt->fetch(PDO::FETCH_ASSOC);
$item_name_stmt = null;
return $item_info['szName'];
} `
And a print_r($item) result before running the function:
Array ( [dlID] => 3.377699720834E+15 [bStorageType] => 0 [dwStorageID] => 254 [bOwnerType] => 0 [dwOwnerID] => 9910 [bItemID] => 0 [wItemID] => 22105 [bLevel] => 24 [bCount] => 1 [bGLevel] => 0 [dwDuraMax] => 1000000 [dwDuraCur] => 999952 [bRefineCur] => 0 [dEndTime] => 2030-03-09 01:09:00 [bGradeEffect] => 5 [bMagic1] => 11 [bMagic2] => 13 [bMagic3] => 54 [bMagic4] => 0 [bMagic5] => 0 [bMagic6] => 0 [wValue1] => 100 [wValue2] => 43 [wValue3] => 130 [wValue4] => 0 [wValue5] => 0 [wValue6] => 0 [dwTime1] => 0 [dwTime2] => 0 [dwTime3] => 0 [dwTime4] => 0 [dwTime5] => 0 [dwTime6] => 0 [bGem] => 0 [wMoggItemID] => 153 )
Trying to get a print_r($item) after running get_item_name($id) function results in no print_r output.