Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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 在与id参数相关的页面中筛选结果_Php_Mysql - Fatal编程技术网

Php 在与id参数相关的页面中筛选结果

Php 在与id参数相关的页面中筛选结果,php,mysql,Php,Mysql,我使用SELECT从表TBL导航中获取所有行。 这些行是:idnav、idnavcat、prognav、progurl $rsnav=mysql\u query($query\u rsnav,$concat)或die(mysql\u error()); $row\u rsnav=mysql\u fetch\u assoc($rsnav) idnavcat代表导航类别。现在我想过滤那个“idnavcat”;并在表格中显示每个类别的结果 <?php do { ?>

我使用SELECT从表TBL导航中获取所有行。 这些行是:idnav、idnavcat、prognav、progurl

$rsnav=mysql\u query($query\u rsnav,$concat)或die(mysql\u error()); $row\u rsnav=mysql\u fetch\u assoc($rsnav)

idnavcat代表导航类别。现在我想过滤那个“idnavcat”;并在表格中显示每个类别的结果

        <?php do { ?>
        <tr>
          <td width="10%"><div align="center"><?php echo $row_rsnav['idnav']; ?></div></td>
          <td width="70%"><?php echo $row_rsnav['navprog']; ?></td>
          <td width="11%"><a href="nav_adj.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/edit.png" alt="" width="32" height="32" border="0" /></a></td>
          <td width="8%"><p><a href="nav_del.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/delete.png" alt="" width="32" height="32" /></a></p>              </td>
        </tr>
        <?php } while ($row_rsnav = mysql_fetch_assoc($rsnav)); ?>
我读出来的是:

foreach ($data as $id => $va){
echo 'blablabla';
}
但它读取整个数组。 我只想显示具有特定idnavcat值的arraylines。 如何做到这一点?
谢谢你的帮助

我不知道你到底想做什么。如果我是对的,您希望实现代码中断结构

首先,您需要按idnavcat对查询进行排序,并尝试执行如下代码:

<?php

[...]

$query = "SELECT * FROM tblnavigation ORDER BY idnavcat;"; 

[...] // you execute the query here and do the rest of the stuff


// fetch the row
$row_rsnav = mysql_fetch_assoc($rsnav);
// stablish a default current category to force headers to be written
$current_category = -1;
do {

    if ($current_category != $row_rsnav['idnavcat']) 
    {
        $current_category = $row_rsnav['idnavcat'];

        // print headers (for example)
        ?>
        <tr>
          <td width="10%">ID NAV</td>
          <td width="70%">NAV PROG</td>
          <td width="19%" colspan="2">CATEGORY: <?php echo $current_category ?></td>
        </tr>
        <?
    }
?>
    <tr>
      <td width="10%"><div align="center"><?php echo $row_rsnav['idnav']; ?></div></td>
      <td width="70%"><?php echo $row_rsnav['navprog']; ?></td>
      <td width="11%"><a href="nav_adj.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/edit.png" alt="" width="32" height="32" border="0" /></a></td>
      <td width="8%"><p><a href="nav_del.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/delete.png" alt="" width="32" height="32" /></a></p></td>
    </tr>
<?php } while ($row_rsnav = mysql_fetch_assoc($rsnav)); ?>

ID导航
导航程序
类别:

但是,由于这种编程方式或多或少难看,我们应该考虑使用SMARTY或任何模板系统来格式化我们的源代码的结果,以便能够快速地修改它,而不会影响很多功能。
<?php

[...]

$query = "SELECT * FROM tblnavigation ORDER BY idnavcat;"; 

[...] // you execute the query here and do the rest of the stuff


// fetch the row
$row_rsnav = mysql_fetch_assoc($rsnav);
// stablish a default current category to force headers to be written
$current_category = -1;
do {

    if ($current_category != $row_rsnav['idnavcat']) 
    {
        $current_category = $row_rsnav['idnavcat'];

        // print headers (for example)
        ?>
        <tr>
          <td width="10%">ID NAV</td>
          <td width="70%">NAV PROG</td>
          <td width="19%" colspan="2">CATEGORY: <?php echo $current_category ?></td>
        </tr>
        <?
    }
?>
    <tr>
      <td width="10%"><div align="center"><?php echo $row_rsnav['idnav']; ?></div></td>
      <td width="70%"><?php echo $row_rsnav['navprog']; ?></td>
      <td width="11%"><a href="nav_adj.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/edit.png" alt="" width="32" height="32" border="0" /></a></td>
      <td width="8%"><p><a href="nav_del.php?id=<?php echo $row_rsnav['idnav']; ?>"><img src="images/delete.png" alt="" width="32" height="32" /></a></p></td>
    </tr>
<?php } while ($row_rsnav = mysql_fetch_assoc($rsnav)); ?>