SQLSRV_FETCH_ARRAY how to store the arrays in a variable

Hi, can someone tell me how to store the arrays retrieved frm a database using sqlsrv_fetch_array to a variable? say for example this is my script:

echo $email;
$sql_int=“SELECT item FROM Inventory WHERE user_email = ‘$email’”;
$resultint = sqlsrv_query($conn,$sql_int);
$sql_loo=“SELECT item FROM Looking WHERE user_email = ‘$email’”;
$resultloo = sqlsrv_query($conn,$sql_loo);
print_r( sqlsrv_errors());
while($row_int = sqlsrv_fetch_array($resultint)){
echo $row_int[‘item’];
print_r( sqlsrv_errors());
}

[COLOR=“#0000FF”]$row_loo = array();
while($row_loo = sqlsrv_fetch_array($resultloo)){
echo $row_loo[‘item’];
print_r( sqlsrv_errors());

}[/COLOR]
$row_loo = sqlsrv_fetch_array($resultloo);
echo $row_loo[‘item’];

$sql=“SELECT user_email FROM Inventory WHERE item = ‘$row_loo’”;
$resulmat = sqlsrv_query($conn,$sql);
print_r( sqlsrv_errors());

while($row = sqlsrv_fetch_array($resultmat)){
echo $row[‘user_email’];
print_r( sqlsrv_errors());

i am getting an error that says the underlined script, has null resource. I knw the problem is in the bold line. $row_loo doesnt have a value. The value is supposed to come frm the blue coloured lines. For some reason, it does echo the values, but outside of the loop the variable is empty. so i added another line ( the red one)outside the loop to fetch array values again, but its still not working. can someone help? I tried echoing some of the values to test and see if they are working by the ways.Thanks in advance. Still a newbie.
Oh by the way, the code is working fine up until the end of the blue lines. The problem with the script starts from the red lines to the bottom. I tried some many things, but its still nt working.

$resulmat = sqlsrv_query($conn,$sql);
print_r( sqlsrv_errors());

while($row = sqlsrv_fetch_array($resultmat)){

Typo :slight_smile:

echo $email;
$sql_int=“SELECT item FROM Inventory WHERE user_email = ‘$email’”;
$resultint = sqlsrv_query($conn,$sql_int);
$sql_loo=“SELECT item FROM Looking WHERE user_email = ‘$email’”;
$resultloo = sqlsrv_query($conn,$sql_loo);
print_r( sqlsrv_errors());

while($row_int = sqlsrv_fetch_array($resultint)){
echo $row_int[‘item’];
print_r( sqlsrv_errors());
}

while($row_loo = sqlsrv_fetch_array($resultloo)){
echo $row_loo[‘item’];
print_r( sqlsrv_errors());
}

echo’will’;
$sql=“SELECT user_email FROM Inventory WHERE item = ‘$row_loo[item]’”;
$resultmat = sqlsrv_query($conn,$sql);
if(sqlsrv_has_rows($resultmat)){
echo ‘success’;
}

while($row = sqlsrv_fetch_array($resultmat)){
echo $row[‘user_email’];
echo ‘willer’;
print_r( sqlsrv_errors());
}

?>

so the dark red part does not echo success. and the green line echoes nothing, not even the willer. by teh way, when i echoed resultmat, it says smtg like resource id8#. so i am guessing that the resultmat does return a values as i am no longer getting any error that its null.
I check my databse many many times and i am very sure that there are datas that it shud match and display.

for some reason. the green part now is not echoing anything. thanks for the help so far, i cant believe i made such a silly error with the spelling but yeah now i have this new prob. will be grateful if you could help


// use the . to concatenate the expanded array element correctly into the sql string
$sql="SELECT user_email FROM Inventory WHERE item = '" . $row_loo[item]. "'";

// add a line of debug here - this is how you prove whether the sql statement is 
// properly constructed - copy the output, paste it into your db, does it get results?
// does it show errors?  RM it when when case is proven
echo $sql;


$resultmat = sqlsrv_query($conn,$sql);
if(sqlsrv_has_rows($resultmat)){
echo 'success';
}

HTH

SO I FOUND A SOLUTION ACTUALLY. SO WHAT I DID WAS:

[FONT=Arial Black]$c=1;
while($row=sqlsrv_fetch_array($resultmat,SQLSRV_FETCH_ARRAY)){

$variablename = ‘loo_email’ . $c;
$$variablename = $resultloo_row[‘user_email’];
$c++;

}[/FONT]
So this basically stores the values from my query as $loo_email1,$loo_email2,$loo_email3 … This is bascially what i wanted. Anyways thanks guys.