I tried your code and didn’t notice anything wrong. To help debug, you could try adding some “print_r” and “echo” code for a better sense of what’s happending
Also, you mentioned that your array is imploded, which to my understanding returns a string with the values of the array in the form [value][separator][value]…, is it still an array when the ‘foreach’ starts? Are you finding that $transactions is empty?
print_r ($paymentr); // <----- ADDED FOR DEBUG
foreach ($paymentr as $v) {
$query = “SELECT id, refid, affid FROM transactions WHERE id = ‘$v’”;
echo $query . "<br/>"; // <----- ADDED FOR DEBUG, (XHTML <br/> closed tag)
$result = mysql_query($query) or die("Query Failed: ".mysql_errno()." - ".mysql_error()."<BR>\n$query<BR>\n");
$trans = mysql_fetch_array($result, MYSQL_ASSOC);
$transactions .= ‘<br>User ID:’.$trans[‘id’].’ – ‘.$trans[‘refid’].’ – ‘.$trans[‘affid’].’’;
}
Or, you could do this, which hits the db less:
foreach ($paymentr as $v) { $in_clause .= “’”.$v."’,"; }
$in_clause = trim($in_clause, ",");
$query = "SELECT id, refid, affid FROM transactions WHERE id IN ($in_clause)";
$result = mysql_query($query) or die("Query Failed: ".mysql_errno()." - ".mysql_error()."<BR>\n$query<BR>\n");
while ( $trans = mysql_fetch_array ( $result, MYSQL_ASSOC ))
{
$transactions .= ‘<br>User ID:’.$trans[‘id’].’ – ‘.$trans[‘refid’].’ – ‘.$trans[‘affid’].’’;
}