I'm having a problem with this script. It works fine for the first category, but not the second.
Output:
Script
DB:
Output:
Script
Code:
<?PHP
$connect = mysql_connect('test.perfora.net', 'test118443323', 'test');
if (!$connect) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('db118443323', $connect);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$sql1 = mysql_query("SELECT * FROM checklist ORDER BY CATEGORY, NAME") or die("Can't get checklist");
$sql2 = mysql_query("SELECT * FROM checklist_categories ORDER BY NAME") or die("Can't Get Categories");
?>
<html>
<head>
<title>Move Out List</title>
</head>
<body>
<?PHP
$i = 1;
while($categories = mysql_fetch_assoc($sql2))
{
print("<h2>" . $categories['NAME'] . "</h1>\n");
while($checklist = mysql_fetch_assoc($sql1))
{
if($checklist['CATEGORY'] == $i)
{
print("<h4>" . $checklist['NAME'] . "</h3>\n");
}
}
$i++;
}
?>
</body>
</html>
<?PHP
mysql_close($connect);
?>
DB:
Code:
--
-- Table structure for table `checklist`
--
CREATE TABLE `checklist` (
`ID` tinyint(3) NOT NULL auto_increment,
`NAME` varchar(40) NOT NULL default '(none)',
`CATEGORY` tinyint(3) NOT NULL default '0',
`DETAILS` varchar(255) NOT NULL default '(none)',
`USER` enum('(none)','User1','User2') NOT NULL default '(none)',
`CHECKED` enum('Yes','No') NOT NULL default 'No',
KEY `ID` (`ID`),
FULLTEXT KEY `DETAILS` (`DETAILS`)
) TYPE=MyISAM AUTO_INCREMENT=4 ;
--
-- Dumping data for table `checklist`
--
INSERT INTO `checklist` VALUES (1, 'Boxframe/Mattress/Futon', 1, 'Need at least a mattress or futon, maybe a frame', '(none)', 'Yes');
INSERT INTO `checklist` VALUES (2, 'Floor Lamp', 1, '(none)', '(none)', 'No');
INSERT INTO `checklist` VALUES (3, 'Couch', 2, 'Hideaway and end piece, will need to reupholster', 'User1', 'Yes');
--
-- Table structure for table `checklist_categories`
--
CREATE TABLE `checklist_categories` (
`ID` tinyint(3) NOT NULL auto_increment,
`NAME` varchar(255) NOT NULL default '(none)',
PRIMARY KEY (`ID`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;
--
-- Dumping data for table `checklist_categories`
--
INSERT INTO `checklist_categories` VALUES (1, 'Bedroom');
INSERT INTO `checklist_categories` VALUES (2, 'Living Room');