如何将php字符串代码传递给html [英] how to pass php string code to html

查看:217
本文介绍了如何将php字符串代码传递给html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能,可以返回我选择的下拉值,该值显然来自数据库.这里的问题是我的下拉列表中的html如以下所示存在于php标签中

i have a function which returns me selected drop down value which obviously coming from DB. problem here is that html of that drop down of mine is existing in php tags as given bellow

<?php function _callback_request_type($value, $primary_key)
   {
            //$q=($value == "") ? "selected=selected" : ""; 
           return '<select name="request_type" id="request_type">
                             <option value="">Request Type</option>
                             <option value="Housing" ($value == "Housing") ? "selected=selected" : "" >Housing</option>
                             <option value="Employment" >Employment</option>
                             <option value="Education" >Education</option>
                             <option value="Finance" >Finance</option>
                             <option value="Welfare" >Welfare</option>
                             <option value="Other" >Other</option>
                           </select>';

   } ?>

问题在这里,它没有给我返回任何返回值,现在我很困惑如何将php字符串值放入此html ..我想要的只是选择了下拉值.请帮我解决这个问题.

Problem is here that it doesn't give me back any return value , and i get confused now how to put php string values in this html.. all i want is selected dropdown value. please help me out from this problem.

推荐答案

我修复了您的代码,可能有效:

I fixed your code a little bit, may work:

<?php 
function _callback_request_type($value, $primary_key){
  $q= (!empty($value)) ? "selected=selected" : ""; 

  return 
  '<select name="request_type" id="request_type">
    <option value="">Request Type</option>
    <option value="Housing" '.(($value == "Housing") ? "selected=selected" : "").' >Housing</option>
    <option value="Employment" >Employment</option>
    <option value="Education" >Education</option>
    <option value="Finance" >Finance</option>
    <option value="Welfare" >Welfare</option>
    <option value="Other" >Other</option>
  </select>';

} 

echo _callback_request_type("Housing", null); //Echoes needed stuff.
?>

这篇关于如何将php字符串代码传递给html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆