0

I have this code which is not working

  <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>

The line that is causing me trouble is

 <?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}");?>

If i give the query as

 <?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");?>

it works fine. But i want it to be dynamic. Valid values for menu_id are 7, 8, 9

Please help

2
  • 1
    You made a typo, it should be outerID, not outerId. PHP is case sensitive. I recommend using copy/paste for variable names, or using a text editor that has autocomplete (try out Sublime Text or Eclipse). Using either copy/paste or autocomplete will save you time and frustration by reducing typos like this one. Commented Oct 20, 2012 at 7:13
  • Thanks everyone for your replies.. Commented Oct 20, 2012 at 8:07

5 Answers 5

2

Try this

<?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});?>

Sign up to request clarification or add additional context in comments.

Comments

2

Your have typo in outerID, not outerId as mentioned by @Abhi Beckert.

$outerId = $outerRow['menu_id'];

You used $outerID in query. So I don't think your query have errors. Correct the typo and try again.

If you like to change the query try like below

$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);

Comments

0

You may try this one

 <?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."");?>

Comments

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);?>

Comments

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");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.