0

我有这段代码不起作用

  <body>
<?php $outerSql = mysql_query("select * from gree_menu"); ?>
<ul>
  <?php
    while($outerRow = mysql_fetch_array($outerSql)) {
      $outerMenu = $outerRow['menu_name'];
      $outerId = $outerRow['menu_id'];
    ?>
      <li>
        <?=$outerMenu; ?>
        <?php $innerSql = mysql_query("SELECT sp.* FROM gree_menu gm INNER JOIN silicon_prod sp ON gm.menu_id = sp.menu_parent_id WHERE gm.menu_id = {$outerID}");?>

        <ul>
          <?php

            while($innerRow = mysql_fetch_array($innerSql)) {
              $innerMenu = $innerRow['prod_name'];
          ?>
            <li><?= $innerMenu;?></li>
            <?php
            }
            ?>
        </ul>
      </li>
    <?php 
    } 
    ?>

</ul>

给我带来麻烦的线路是

 <?php $innerSql = mysql_query("SELECT sp.* FROM gree_menu gm INNER JOIN silicon_prod sp ON gm.menu_id = sp.menu_parent_id WHERE gm.menu_id = {$outerID}");?>

如果我将查询作为

 <?php $innerSql = mysql_query("SELECT sp.* FROM gree_menu gm INNER JOIN silicon_prod sp ON gm.menu_id = sp.menu_parent_id WHERE gm.menu_id = 7");?>

它工作正常。但我希望它是动态的。menu_id 的有效值为 7、8、9

请帮忙

4

5 回答 5

2

尝试这个

<?php $innerSql = mysql_query("SELECT sp.* FROM gree_menu gm INNER JOIN silicon_prod sp ON gm.menu_id = sp.menu_parent_id WHERE gm.menu_id =".{$outerID});?>

于 2012-10-20T07:08:56.030 回答
2

您在outerID 中有错字,而不是@Abhi Beckert 提到的outerId。

$outerId = $outerRow['menu_id'];

$outerID在查询中使用。所以我认为您的查询没有错误。更正错字并重试。

如果您想更改查询,请尝试如下

$innerSql = mysql_query("SELECT sp.* FROM gree_menu gm 
          INNER JOIN silicon_prod sp ON gm.menu_id = sp.menu_parent_id
          WHERE gm.menu_id = ".$outerId);
于 2012-10-20T07:23:38.230 回答
0

你可以试试这个

 <?php $innerSql = mysql_query("SELECT sp.* FROM gree_menu gm INNER JOIN silicon_prod sp ON gm.menu_id = sp.menu_parent_id WHERE gm.menu_id = ".$outerID."");?>
于 2012-10-20T07:28:03.923 回答
0
<?php $innerSql = mysql_query("SELECT sp.* FROM gree_menu gm INNER JOIN silicon_prod sp ON gm.menu_id = sp.menu_parent_id WHERE gm.menu_id = ".$outerID);?>
于 2012-10-20T07:29:02.853 回答
0
mysql_query("SELECT sp.* FROM gree_menu gm 
INNER JOIN silicon_prod sp ON gm.menu_id = sp.menu_parent_id 
WHERE gm.menu_id =$outerID");
于 2012-10-20T07:29:36.007 回答