converting html to php with sql-query -
i want convert following code html file php file , print 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.* categories categories.id!='' order 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 $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 print , how syntax like? because of
mysql, endforeach , endif
i new php. lot in advance! marcel
that's should 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.* categories categories.id!='' order 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 $k=>$v) $output.='<option style="width:50px;" value="'.$_post['id'].'"><'.$_post['cat_name'].'></option>'; endforeach; endif;
its difficult separate it. move loop function returns html string want. references $output are: html, or html functions return html.
<?php // getcatsasoptions returns: string of html containing option list of cats function getcatsasoptions(){ $catsoptions="empty of cats"; mysql_query("set names utf8"); $cats = $db->get_rows("select categories.* categories categories.id!='' order categories.cat_name asc"); if(!empty($cats)): //as other comments : colons $catsoptions=""; foreach($cats $k=>$v): $catsoptions.='<option style="width:50px;" value="'.$_post['id'].'"><'.$_post['cat_name'].'></option>'; endforeach; endif; return $catsoptions; }
with can use $output.='html'
$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" />'; $output.='<select name="products" class="" id="edit-products"><option style="width:100%;" value="">alle kategorien</option>'; $output.=getcatsasoptions(); $output.='</select>'; ...
then output html string
echo $output; ///or print($output); ...
i hope idea useful [please take care syntax in answer]
Comments
Post a Comment