I want to convert the following code from a html file to a php file and print the following code:
HTML
<!-- begin search box -->
<form method="post" action="./index.php" accept-charset="UTF-8" method="post" id="clinic-finder-form" class="clear-block" class="clear-block">
<input type="text" maxlength="128" name="address" id="address" size="100px" value="" class="form-text" autocomplete="off" />
<?php
// support unicode
mysql_query("SET NAMES utf8");
$cats = $db->get_rows("SELECT categories.* FROM categories WHERE categories.id!='' ORDER BY
categories.cat_name ASC");
?>
<select name="products" class="" id="edit-products"><option style="width:100%;" value="">Alle Kategorien</option>
<?php if(!empty($cats)): ?>
<?php foreach($cats as $k=>$v): ?>
<option style="width:50px;" value="<?php echo $v['id']; ?>"><?php echo $v['cat_name']; ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<!-- search box buttons -->
<input type="hidden" name="form_build_id" id="form-0168068fce35cf80f346d6c1dbd7344e" value="form-0168068fce35cf80f346d6c1dbd7344e" />
<input type="hidden" name="form_id" id="edit-clinic-finder-form" value="clinic_finder_form" />
<!-- button -->
<input type="submit" name="op" id="edit-submit" value="Suchen" class="btn btn-primary" />
</form>
<!-- end search box -->
How can I do this with print and how does the syntax look like? Especially because of the
mysql, endforeach and endif
I am very new to php. Thanks a lot in advance! Marcel
That's what it should look like:
$output.='<div id="main">
<div id="searchbox">
<form method="post" action="./index.php" accept-charset="UTF-8" method="post" id="clinic-finder-form">
<input type="text" maxlength="128" name="address" id="address" size="50px" value="" class="form-text" autocomplete="off" />
<input type="hidden" name="form_build_id" id="form-0168068fce35cf80f346d6c1dbd7344e" value="form-0168068fce35cf80f346d6c1dbd7344e" />
<input type="hidden" name="form_id" id="edit-clinic-finder-form" value="clinic_finder_form" /><!-- button -->
<input type="submit" name="op" id="edit-submit" value="Suchen" class="btn btn-primary" />';
mysql_query("SET NAMES utf8");
$cats = $db->get_rows("SELECT categories.* FROM categories WHERE categories.id!='' ORDER BY
categories.cat_name ASC");
$output.='<select name="products" class="" id="edit-products"><option style="width:100%;" value="">Alle Kategorien</option>';
if(!empty($cats))
foreach($cats as $k=>$v)
$output.='<option style="width:50px;" value="'.$_POST['id'].'"><'.$_POST['cat_name'].'></option>';
endforeach;
endif;