php如何使用子标题列出
对于php环境,我尝试使用php和MySQL数据库创建一个列表。见下文 -----我的输出要求信息------ 主页标题 子目1(品牌类型的内容=1) 1111 2222 3333 4444(我希望这些作为超链接在同一网页中打开) 子目2(品牌类型=2) 5555 6666 7777 8888(我希望这些作为超链接在同一网页中打开) 下面是我的代码 //连接到数据库服务器php如何使用子标题列出,php,html,mysql,Php,Html,Mysql,对于php环境,我尝试使用php和MySQL数据库创建一个列表。见下文 -----我的输出要求信息------ 主页标题 子目1(品牌类型的内容=1) 1111 2222 3333 4444(我希望这些作为超链接在同一网页中打开) 子目2(品牌类型=2) 5555 6666 7777 8888(我希望这些作为超链接在同一网页中打开) 下面是我的代码 //连接到数据库服务器 include 'xxxxxyyyyzzzz.php'; $conn = mysql_connect($db_host,$d
include 'xxxxxyyyyzzzz.php';
$conn = mysql_connect($db_host,$db_username,$db_password);
mysql_connect($db_host,$db_username,$db_password) or die (mysql_error ());
mysql_select_db($db_database,$conn) or die(mysql_error()); // Select database
echo "<h1>main webpage heading</h1>";
echo "<h3>my subheading</h3>";
// SQL query
$strSQL = "SELECT * FROM table name WHERE brand type='1','Software' ORDER BY serviceName ASC";
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
// Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {
$strName = $row['serviceName'];
$strLink = "<a href = 'person.php?id = " . $row['ID'] . "'>" . $strName . "</a>";
// List link
echo "<li>" . $strLink . "</li>";
// include 'emaild.php';
}
// Close the database connection
mysql_close();
?>
</ul>
</body>
</html>
end of my code
包括“XXXXX YYYYZZZZ.php”;
$conn=mysql\u connect($db\u主机,$db\u用户名,$db\u密码);
mysql\u connect($db\u主机,$db\u用户名,$db\u密码)或die(mysql\u错误());
mysql_选择_db($db_database,$conn)或die(mysql_error());//选择数据库
回显“主网页标题”;
呼应“我的副标题”;
//SQL查询
$strSQL=“从表名中选择*,其中品牌类型为='1','Software'按serviceName ASC排序”;
//执行查询(记录集$rs包含结果)
$rs=mysql\u查询($strSQL);
//循环记录集$rs
while($row=mysql\u fetch\u数组($rs)){
$strName=$row['serviceName'];
$strLink=“”;
//列表链接
echo“”$strLink. ”;
//包括“emaild.php”;
}
//关闭数据库连接
mysql_close();
?>
我的代码结束了
我得到了一个列表,但必须手动输入副标题(例如,根据品牌类型,echo“主页名”echo“副标题”)
- 如何调整我的代码,使我的品牌类型=1时,它打印标题品牌类型1,然后在其下方打印该品牌1的项目,如果没有项目,则它不打印副标题(品牌类型=1),并转到下一个打印副标题品牌类型=2,并列出其下方的内容
- 我可以将每个副标题下的列表项作为网页的链接,但它不起作用,我如何使这些列表项在同一网页上打开,并提供更多产品详细信息,我将使用“后退”按钮转到上一个列表网页…提前感谢..singhy
SendBrandListings(1, "Brand 1 Header");
SendBrandListings(2, "Brand 2 Header");
function SendBrandListings($brandId, $heading){
echo "<h3>$heading</h3>";
$strSQL = "SELECT * FROM table name WHERE brand type='$brandId','Software' ORDER BY serviceName ASC";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
$strName = $row['serviceName'];
$strLink = "<a href = 'person.php?id = " . $row['ID'] . "'>" . $strName . "</a>";
echo "<li>" . $strLink . "</li>";
}
}
a) 使用mysqli_xx而不是mysql_xx函数。b)
- 中。c) 多级列表是通过将新列表放入
- 中创建的HTML格式,例如
- 项目
- 内部项目
中。注#2:我没有测试这段代码,因此可能会有一些小错误。您好,432无法打开最后一条消息,也无法发布代码片段,谢谢,我仍在努力…我设法找到了其他更简单的方法来基本上分割我从数据库中获得的列表,然后根据品牌类型输入输出的副标题!,我可以设法以升序获得所有内容,然后我尝试将品牌类型标题放入列表中!,谢谢Singhihi dutchie谢谢你的帮助,成功地让它工作了,但有两个问题,第一个品牌类型的副标题没有出现,没有按升序排列,其余的都可以。我无法在$strSQL=“SELECT*FROM WHERE id=”下的同一网页(person.php)代码中获取要打开的列表超链接$_获取[“id”]$rs=mysql\u查询($strSQL);回显“ID:”$行[“ID”]。" " . $第[“guUrl”]行。""; echo“可用性:”$第[“可用性”]行。"";} 此按钮返回到上一个列表网页。此网页提供了两个字段的更多详细信息…谢谢- ..
$c = 0; //Variable to keep count of categories $lastBrand = ''; //Declare a variable to track the last displayed Brand Name while($row = mysql_fetch_array($rs)) { //If the brand name has changed, display it and update the tracking variable if ($lastBrand != $row['brandName']){ $lastBrand = $row['brandName']; //If this isn't the first category, end the previous list. if ($c>0) echo "</ul>"; echo '<h3>'.$row['brandName'].'</h3><ul>'; $c++; } $strName = $row['serviceName']; $strLink = "<a href = 'person.php?id = " . $row['ID'] . "'>" . $strName . "</a>"; echo "<li>" . $strLink . "</li>"; }
- 项目