Reputation: 11
Sorry for such an nOOb question, but I have been work on this for a while now and can't figure out how to break in and out of the php - specifically when it get to the do while loop below. Cna anyone help please?
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-->';
}
Upvotes: 0
Views: 151
Reputation: 2986
This might work, you're adding PHP tag that might be the reason.
<?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>';
}
?>
Upvotes: 0
Reputation: 3205
Use a HEREDOC so there will be no need of quotes or php start/end tags when placing a variable. So your code would look like:
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;
}
Upvotes: 0
Reputation: 324780
You're already in PHP when you're putting the string into the variable. You don't need more <?php
tags, you just need a close quote and a ;
.
<?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-->';
}
?>
Upvotes: 1