0
我有下面的代碼從 數據庫中創建類別和子類別我如何引用一個動態創建的列表PHP
function displayChild($parent)
{
include 'connect.php';
$parentid=$parent;
$catSql='select* from categories where parentid='.$parentid.'';
$result=$con->query($catSql);
echo '<div><ul class='.'ul'.$parentid.'>';
while ($rows=$result->fetch_assoc())
{
echo '<li><a href="#">'.mb_strtoupper($rows['catName']).'</a></li>';
displayChild($rows['catId']);
}
echo '</ul></div>';
}
displayChild('0');
的CSS位應該是如下
@charset "utf-8";
.ul0{}
.ul1{}
.ul2{}
.
.
.
.uln{}
由於第一
標籤出現在while循環之外時,它會形成一個非常奇怪的列表,當我引用它時,在while()循環中輸入它也不是一個選項。請幫助
您的代碼可能容易受到SQL注入攻擊。您應該使用[mysqli](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)或[PDO](http://php.net/manual/en/pdo.prepared- statement.php)按照[本文]中描述的準備語句(http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)。 –