如何使用PHP显示单选按钮值 [英] How to display radio button value using PHP
问题描述
下面是代码表格:
< 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屋!