涉足另一个“程序员”的世界PHP/MySQL 代码

发布于 2024-11-04 19:22:44 字数 2172 浏览 0 评论 0原文

好吧,我得到了这段有问题的代码:

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


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

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

它基本上突然停止工作了。如果我删除此代码,则对该文件的要求会顺利进行,因此我假设此处存在问题。我已经尝试重新格式化大约 5 次了,所以我想一定是我的眼睛漏掉了一些东西。

有什么建议吗?对此代码的状态表示歉意..尝试一次更好地修复它..

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']; ?>&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 Submenu-->


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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热情消退 2024-11-11 19:22:44

不确定这是复制/粘贴错误还是实际问题,但看起来 PHP 打开了,然后切换到常规 HTML 而不关闭 PHP 块。 (我可能没有使用正确的术语;我不是 PHP 开发人员 - 我只在智选假日酒店住过一次 :p)

<!-- Begin the Product Group Submenu -->
                       <ul>
<?php do  { ?> 
    <li><a href="prodgrouppg.php?groupid=<?php echo $row_menugroup['GroupID']; ?>&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 -->

通过使用 ASP/VBScript,我发现迁移一个不断切换的页面,并且从代码/html 到直接代码可以帮助发现一些奇怪的事情,例如忘记关闭块或找到收紧循环的方法。

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']; ?>&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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文