I've been trying to figure this out for hours:
In phpMyAdmin, entering this gives the correct results of 43 items returned:
SELECT company, folder, lastaccess FROM clients WHERE salesperson IN (2, 21) AND status = 'enabled' ORDER BY company
Salesperson 2 has 39 companies in the database, Salesman 21 has 4 companies.
But when I try to turn it into a prepared statement, I only get back the the 39 rows of the first salesman. No errors, no warnings.
It's as if mySQL is simply ignoring anything after the first number in $teamlist. I can change the numbers around, and I get corresponding results, but only on the first item in $teamlist. All the others after the first are ignored.
$teamlist = "2, 21";
$sql = 'SELECT company, folder, lastaccess FROM clients WHERE salesperson IN (?) AND status = \'enabled\' ORDER BY company';
$conn = dbConnect('query'); // Call to a function with mySQL user and passwd
$result = $conn->stmt_init();
if ($result->prepare($sql)) {
$result->bind_param('s', $teamlist); // Have also tried setting the type to 'i' with no change in problem
$result->execute();
$result->bind_result($company, $folder, $lastaccess);
$result->store_result();
}
$numrows = $result->num_rows();
echo 'numrows = '. $numrows; //Produces 39 rows, should be 43
while ($result->fetch()) {
echo "<p>". $company ." | ". $folder ." | ". $lastaccess . "</p>";
}
What the heck am I doing wrong?
I'm using:
PHP Version 5.2.4
mySQL 5.0.24a-standard
On an Apple Intel laptop running MacOS X 10.5.2