I have a table with various auctions, where each record has both a username and a category. More than likely, there will be multiple records with the same username and category. There are four different types of categories.
I am wondering if it would be possible, given the prepared query below, to have the second bound parameter be the result of looping through an array containing the 4 categories, and if I could dynamically assign the result to an array?
$countAuctionsQuery = "select COUNT(USERNAME, SUBCAT) from AUCTIONS where username = ? AND SUBCAT = ?";
if ($getRecords = $con->prepare($countAuctionsQuery))
{
$getRecords->bind_param("ss", $username, $subcat);
$getRecords->execute();
$getRecords->bind_result($numRecords);
}
edit:
An example of data
Auctions
username itemnumber cost category
------------------------------------------------
fredx 222 $33 fake
fredx 123 $43 fake
timo 765 $54 fake
fredx 987 $99 sold
bobk 233 $77 fake
wenx 11 $12 ok
fredx 23 $31 ok
fredx 723 $73 fake
wenx 44 $88 ok
So, for username fredx and category fake, 3 should be returned.
For username fredx and category sold, 1 should be returned
For username timo and category fake, 1 should be returned
For username wenx and category ok, 2 should be returned.
I want to be able to print out like so:
Fake items: $numfake items or category['fake']
OK items: $numok items or category['ok']
Sold items: $numsold items or category['sold']