如何使用PHP显示单选按钮值 [英] How to display radio button value using PHP

查看:132
本文介绍了如何使用PHP显示单选按钮值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个表单,用户用一些单选按钮填写。单选按钮的值传递给MySQL。我现在想从数据库中提取这些值,将它们显示在不同页面的表格中,并使用span标签对它们应用不同的样式。



下面是代码表格:

 < input class =radio_styletype =radioname =job_typevalue =fulltime />全职<峰; br /> 
< input class =radio_styletype =radioname =job_typevalue =parttime/>兼职< br />

以下是我要显示的页面的代码:

 < div class ='job_type_div'> 
<?php if($ job_type =='fulltime'){?>
< span class ='job_type_style'>
<?php echo $ row ['job_type']; ?>
< / span>
<?php if($ job_type =='parttime'){?>
< span class ='job_type_style2'>
<?php echo $ row ['job_type']; ?>
< / span>
<?php}?>
<?php}?>
< / div>

理想情况下,全职值将有一种样式,parttime值会有另一种样式样式。但是当我尝试运行这段代码时,没有任何反应。我肯定会正确连接到数据库。行名被正确标记为job_type。任何关于我可能会出错的想法?任何帮助将不胜感激:)

解决方案

在您的php中可能会出现问题。有没有逻辑?

  $ job_type = null; 
if($ job_type =='fulltime'){
...
if($ job_type =='parttime'){
...
}
}

是否设置了$ job_type变量?可能你需要这样的东西:

 < div class ='job_type_div'> 
<?php if($ row ['job_type'] =='fulltime'){?>
< span class ='job_type_style'>
<?php echo $ row ['job_type']; ?>
< / span>
<?php} elseif($ row ['job_type'] =='parttime'){?>
< span class ='job_type_style2'>
<?php echo $ row ['job_type']; ?>
< / span>
<?php}?>
< / div>


So I have a form that users fill out with some radio buttons. The values from the radio buttons get passed to MySQL. I now want to pull those values from the database, display them in a table on a different page, and apply different styles to them with span tags.

Here's the code from the form:

<input class="radio_style" type="radio" name="job_type" value="fulltime"/>Full-time<br/>
<input class="radio_style" type="radio" name="job_type" value="parttime"/>Part-time<br />

Here's the code for the page where I want to display it:

<div class='job_type_div'>
    <?php if($job_type=='fulltime') {?>
        <span class='job_type_style'>
            <?php echo $row['job_type']; ?>
        </span>
   <?php if($job_type=='parttime') {?>
        <span class='job_type_style2'>
            <?php echo $row['job_type']; ?>
        </span>
            <?php } ?>
    <?php } ?>
</div>

So ideally, the "fulltime" value will have one style and the "parttime" value will have another style. But when I try running this code, nothing happens. I'm definitely connecting to the database correctly. And the row name is properly labelled "job_type". Any ideas on where I might be going wrong? Any help would be greatly appreciated :)

解决方案

may be problem in your php. Is there some logic?

$job_type=null;
if($job_type=='fulltime'){
   ...
   if($job_type=='parttime'){
      ...
   }
}

did you set $job_type variable? May be you need something like this:

<div class='job_type_div'>
    <?php if($row['job_type']=='fulltime') {?>
        <span class='job_type_style'>
            <?php echo $row['job_type']; ?>
        </span>
   <?php } elseif($row['job_type']=='parttime') {?>
        <span class='job_type_style2'>
            <?php echo $row['job_type']; ?>
        </span>
    <?php } ?>
</div>

这篇关于如何使用PHP显示单选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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