【发布时间】:2013-12-16 19:33:55
【问题描述】:
我刚刚得到
second
secondsecond
这是我的代码
function getListaa($id){
$sql = "select * from programs where itemRoot = '".$id."'";
$strss = "";
$this->dao1 = new DataAccess("localhost", "root", "", "ecommercedb");
$this->dao1->fetch($sql);
while(($rows = $this->dao1->getNextRow()) != null)
{
if (($this->dao1->executeNum("select * from programs where itemRoot = '".$rows['itemId']."'")) > 0)
{
if($id != 0) $strss .= "".$rows['itemName'];
$strss .= "";
$strss .= $this->getListaa($rows['itemId']);
$strss .= "";
if($id != 0) $strss .= " ";
}
else
{
$strss = "".$rows['itemName']." ";
}
}
return $strss;
}
这是我的桌子
--
-- Table structure for table `programs`
--
CREATE TABLE IF NOT EXISTS `programs` (
`itemId` int(11) NOT NULL AUTO_INCREMENT,
`itemName` varchar(250) NOT NULL,
`itemPrice` float DEFAULT NULL,
`itemDesc` text,
`itemRoot` int(11) NOT NULL,
`itemDateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`itemId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
--
-- Dumping data for table `programs`
--
INSERT INTO `programs` (`itemId`, `itemName`, `itemPrice`, `itemDesc`, `itemRoot`, `itemDateTime`) VALUES
(1, 'root', NULL, NULL, 0, '2013-12-15 13:22:03'),
(3, 'second', NULL, NULL, 1, '2013-12-15 13:22:13'),
(4, 'frist', NULL, NULL, 1, '2013-12-15 13:22:36'),
(5, 'secondfrist', NULL, NULL, 3, '2013-12-15 13:23:46'),
(6, 'secondsecond', NULL, NULL, 3, '2013-12-15 13:23:46'),
(7, 'fristfrist', NULL, NULL, 4, '2013-12-15 13:24:02');
这是我的数据
这是数据访问层代码
conn = mysql_pconnect($host, $user, $pass);
mysql_select_db($dbname, $this->conn);
}
/**
* Execute a query like insert, delete or update
* @param $sql string
* @return void
*/
function execute($sql) {
return mysql_query($sql,$this->conn);
}
function executeNum($sql) {
return mysql_num_rows(mysql_query($sql,$this->conn));
}
/**
* Fetches a query resources and stores it in a local member
* @param $sql string
* @return void
*/
function fetch($sql) {
$this->result = mysql_query($sql,$this->conn);
}
/*function getRowsNum(){
return $this->result->num_rows;
}*/
/**
* Returns an associative array of a query row
* @return Array
*/
function getNextRow() {
if( $row = mysql_fetch_array($this->result) )
return $row;
else
return null;
}
}
?>
【问题讨论】: