Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php如何使用子标题列出_Php_Html_Mysql - Fatal编程技术网

php如何使用子标题列出

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

对于php环境,我尝试使用php和MySQL数据库创建一个列表。见下文

-----我的输出要求信息------

主页标题

子目1(品牌类型的内容=1)

1111

2222

3333

4444(我希望这些作为超链接在同一网页中打开)

子目2(品牌类型=2)

5555

6666

7777

8888(我希望这些作为超链接在同一网页中打开)

下面是我的代码 //连接到数据库服务器

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格式,例如
      • 项目
        • 内部项目
      您好,谢谢您的快速响应,是的,品牌名称在同一个表中,我想做它的动态,而不是手动,如果某些品牌类型不存在,那么我不需要打印它的副标题…节省时间。如何测试您发送给我的代码,我需要某种循环,这样,如果一个品牌类型不存在,那么它将转到下一个品牌类型,直到品牌类型名称完成,这可能吗。。?再次感谢…SinghiHi dutchie432谢谢,我会相应地调整我的代码,并回复我的状态谢谢…SinghiYou收到了。注意:代码已更新,以将列表包含在适当的
        ..
      中。注#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>";
      }