开发者

Wading through another "programmer's" PHP/MySQL code

Ok so I've got this piece of offending code:

<!-- Begin the Product Group Submenu -->
                       <ul>
<?php do  { ?> 
    <li><a href="prodgrouppg.php?groupid=<?php echo $row_menugroup['GroupID']; ?>&amp;groupname=<?php echo $row_menugroup['GroupName']; ?>"><?php echo $row_menugroup['GroupName']; ?></a>

<!-- Retrieve the individual products related to the Group -->                               
<?php                               
$groupprod_menuprod = "-1";
if (isset($row_menugroup['GroupID'])) {
  $groupprod_menuprod = (get_magic_quotes_gpc()) ? $row_menugroup['GroupID'] :     addslashes($row_menugroup['GroupID']);
}
mysql_select_db($database_conn_atex, $conn_atex);
$query_menuprod = sprintf("SELECT products.ProductID, products.ProductName,     products.ProductGroup FROM products WHERE products.ProductGroup=%s ORDER BY products.ProductName", GetSQLValueString($groupprod_menuprod, "int"));
$menuprod = mysql_query($query_menuprod, $conn_atex) or die(mysql_error());
$row_menuprod = mysql_fetch_assoc($menuprod);
$totalRows_menuprod = mysql_num_rows($menuprod);
?>

<!-- Begin the product submenu (final menu) -->

<ul>
<? $row_menuprod = mysql_fetch_assoc($menuprod)) 
{
    echo 
    <li>
        <a href="productpg.php?prodid=<?php echo $row_menuprod['ProductID']; ?>">
            <? echo $row_menuprod['ProductName']; ?>
        </a>
    </li>
    </ul> <!-- end of Product Submenu -->
    </li>
         <?php } while ($row_menugroup = mysql_fetch_assoc($menugroup)); ?>
            </ul> <!-- end of Group Submenu -->
        </li>
        <?php } while ($row_menusubcat = mysql_fetch_assoc($menusubcat)); ?>
    </ul> <!--end of Subcategory Submen开发者_JAVA技巧u-->


</li> <!--end of Category Submenu-->
<?php } while ($row_menupaging = mysql_fetch_assoc($menupaging)); ?>

 </ul> <!--end of Menu -->

Which basically just stopped working out of nowhere. If I delete this code, require for this file goes through OK so I'm assuming something in here is the problem. I've tried reformatting this about 5 times already so I think there must be something my eye is missing.

Any suggestions? Apologies for the state of this code.. trying to fix it up nicer one piece at a time..


Not sure if this was a copy/paste error, or the actual issue, but it looks like there's a PHP open, then a switch to regular HTML without closing the PHP block. (I may not be using the right terms; I'm not a PHP developer - I just stayed at a Holiday Inn Express once :p )

<!-- Begin the Product Group Submenu -->
                       <ul>
<?php do  { ?> 
    <li><a href="prodgrouppg.php?groupid=<?php echo $row_menugroup['GroupID']; ?>&amp;groupname=<?php echo $row_menugroup['GroupName']; ?>"><?php echo $row_menugroup['GroupName']; ?></a>

<!-- Retrieve the individual products related to the Group -->                               
<?php                               
$groupprod_menuprod = "-1";
if (isset($row_menugroup['GroupID'])) {
  $groupprod_menuprod = (get_magic_quotes_gpc()) ? $row_menugroup['GroupID'] :     addslashes($row_menugroup['GroupID']);
}
mysql_select_db($database_conn_atex, $conn_atex);
$query_menuprod = sprintf("SELECT products.ProductID, products.ProductName,     products.ProductGroup FROM products WHERE products.ProductGroup=%s ORDER BY products.ProductName", GetSQLValueString($groupprod_menuprod, "int"));
$menuprod = mysql_query($query_menuprod, $conn_atex) or die(mysql_error());
$row_menuprod = mysql_fetch_assoc($menuprod);
$totalRows_menuprod = mysql_num_rows($menuprod);
?>

<!-- Begin the product submenu (final menu) -->

<ul>
<? $row_menuprod = mysql_fetch_assoc($menuprod)) 
{
    echo ?> <!-- ### close goes here ### -->
    <li>
        <a href="productpg.php?prodid=<?php echo $row_menuprod['ProductID']; ?>">
            <? echo $row_menuprod['ProductName']; ?>
        </a>
    </li>
    </ul> <!-- end of Product Submenu -->
    </li>
         <?php } while ($row_menugroup = mysql_fetch_assoc($menugroup)); ?>
            </ul> <!-- end of Group Submenu -->
        </li>
        <?php } while ($row_menusubcat = mysql_fetch_assoc($menusubcat)); ?>
    </ul> <!--end of Subcategory Submenu-->


</li> <!--end of Category Submenu-->
<?php } while ($row_menupaging = mysql_fetch_assoc($menupaging)); ?>

 </ul> <!--end of Menu -->

From working with ASP/VBScript, I've found that migrating a page that keeps switching in and out of code/html to straight code can help find the little oddities like forgetting to close out a block or finding a way to tighten up a loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜