簡體   English   中英

闖入和闖出PHP

[英]Break in and out of php

對這樣的nOOb問題很抱歉,但是我已經為此工作了一段時間,無法弄清楚如何闖入和闖出php-特別是當它進入下面的do while循環時。 CNA有人幫忙嗎?

if (!$_POST){
$display .= '<div class="aptitle">
            <h2>Add Product</h2>
          </div><!-- aptitle -->

          <div class="apsubtitle">
            <h3>Step 1 of 6</h3>
          </div><!-- apsubtitle -->

          <div class="selectcategorytitle">Please select a category for your item</div><!--selectcategorytitle-->
          <div class="selectcategory">
          <form action="addproducts2.php" method="post" enctype="multipart/form-data" name="step1">
             <div class="selected">Category: <select name="category" class="addproductselect" value=" ' . $selectedcategory . ' " id="select">
                <option value="0">Select a Category</option>
                <?php do { ?>

                <option value="<?php echo $categorylist['pk_cat_id'];?>">
                <?php echo $categorylist['category']; ?> </option>
                <?php } while ($categorylist = mysql_fetch_assoc($category_query)); ?>
             </select>
             <input name="submit" class="submitbtn" type="submit" value="Next Step" /></div><!--selected -->
          </form>

          </div><!--selectcategory-->';
}

將字符串放入變量時,您已經在使用PHP。 您不需要更多的<?php標簽,只需要一個引號和一個;

<?php
if (!$_POST){
$display .= '<div class="aptitle">
                <h2>Add Product</h2>
            </div><!-- aptitle -->

            <div class="apsubtitle">
                <h3>Step 1 of 6</h3>
            </div><!-- apsubtitle -->

            <div class="selectcategorytitle">Please select a category for your item</div><!--selectcategorytitle-->
            <div class="selectcategory">
                <form action="addproducts2.php" method="post" enctype="multipart/form-data" name="step1">
                    <div class="selected">Category:
                        <select name="category" class="addproductselect" value=" ' . $selectedcategory . ' " id="select">
                            <option value="0">Select a Category</option>';

do {
    $display .= '<option value="' . $categorylist['pk_cat_id'] . '">' . $categorylist['category']; . '</option>';
} while ($categorylist = mysql_fetch_assoc($category_query));


$display .= '</select>
<input name="submit" class="submitbtn" type="submit" value="Next Step" /></div><!--selected -->
          </form>

          </div><!--selectcategory-->';
}
?>

使用HEREDOC,以便在放置變量時不需要引號或php開始/結束標簽。 因此您的代碼如下所示:

if (!$_POST){

do {
    $more_options = '<option value="' . $categorylist['pk_cat_id'] . '">' . $categorylist['category'] . '</option>';
} while ($categorylist = mysql_fetch_assoc($category_query));


$display .= <<<HEREDOC
        <div class="aptitle">
            <h2>Add Product</h2>
          </div><!-- aptitle -->

          <div class="apsubtitle">
            <h3>Step 1 of 6</h3>
          </div><!-- apsubtitle -->

          <div class="selectcategorytitle">Please select a category for your item</div><!--selectcategorytitle-->
          <div class="selectcategory">
          <form action="addproducts2.php" method="post" enctype="multipart/form-data" name="step1">
             <div class="selected">Category: <select name="category" class="addproductselect" value="$selectedcategory" id="select">
                <option value="0">Select a Category</option>
                $more_options
             </select>
             <input name="submit" class="submitbtn" type="submit" value="Next Step" /></div><!--selected -->
          </form>

      </div><!--selectcategory-->';

HEREDOC;
}

這可能有效,您正在添加PHP標記可能是原因。

<?php

if (!$_POST) {
    $display .= '<div class="aptitle">
            <h2>Add Product</h2>
          </div><!-- aptitle -->

          <div class="apsubtitle">
            <h3>Step 1 of 6</h3>
          </div><!-- apsubtitle -->

          <div class="selectcategorytitle">Please select a category for your item</div><!--selectcategorytitle-->
          <div class="selectcategory">
          <form action="addproducts2.php" method="post" enctype="multipart/form-data" name="step1">
             <div class="selected">Category: <select name="category" class="addproductselect" value=" ' . $selectedcategory . ' " id="select">
                <option value="0">Select a Category</option>';
    do {
        $display .= '<option value=" ' . $categorylist['pk_cat_id'] . '">
    ' . $categorylist['category'] . ' </option>';
    } while ($categorylist = mysql_fetch_assoc($category_query));
    $display .= '</select>
    <input name="submit" class="submitbtn" type="submit" value="Next Step" /></div>
</form>
</div>';
}
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM