create a recordset for each category to return the records for that category: for example:
rsCatA:
SELECT widgetID FROM widgets WHERE category = 'categoryA'
then use a recordset repeat to add each id to an array;
<?php
$categoryA = array();
do {
$categoryA[] = $row_rsCatA['widgetID'];
} while ($row_rsCatA = mysql_fetch_assoc($rsCatA));
?>
you can display the ID's as a comma separated list using this code:
<?php echo(implode(", ",$categoryA)); ?>