根据数据库提取值设置选定的值 [英] Set Selected Value Based On Database Fetched Value
问题描述
在SELECT类型输入中的值,手动提供。
实验:
为了显示我的逻辑关于如何做到这一点,我试过这段代码
// $ query2 ['via']将产生从数据库
获取的值< option> - < / option>
< option value ='现金'>现金< / option>
< option value ='银行转帐'>银行转帐< / option>
< option value ='信用卡'>信用卡< / option>
< option value ='检查'>检查< / option>
< option value ='其他'>其他< / option>
< / select>
实验结果:
不会工作
所需输出: 我其实只是想要该SELECT类型输入,显示与提取的数据库值完全相同的值。任何想法如何解决这个问题?
感谢您
感谢您的Stackoverflow社区。我不会停止说谢谢。顺便说一句,我纯粹要求学习和知识分享。我接受任何评论(与此问题相关的信息)。
但请不要评价我,我只是要求代码。我实际上学会了如何基于代码本身进行编码,然后适应恰当的代码,对库不熟悉,我仍然是一名大学生。在我自己尝试之前,我不会问。有些人在最近的问题上评论过我。对这个社区来说这不是很好的行为。我正在学习,我们正在学习。
所以再次感谢您。
您可以更改您的代码:
< select name ='slPayment'>
< option> - < / option> $($ query $ ['via'] =='Cash')?'selected =selected':'')。value ='Cash'> Cash< / option>
< option。(($ query2 ['via'] =='Bank Transfer')?'selected =selected':'')。value ='Bank Transfer'> Bank Transfer< /选项> ($ query2 ['via'] =='Credit Card')?'selected =selected':'')。value ='信用卡'>信用卡< /选项> $($'$'$'''''')'('''''''''''''')'(''''''''''''''''''''检查'''''') $('
< option'。(($ query2 ['via'] =='Others')?'selected =selected':'')。value ='Others'> Others< / option>
< / select>
Case :
Hi, Stackoverflow community.
I want to set selected value on SELECT type input based on fetched value from database table column. So if db table column contain "A", SELECT type input will also show "A".
Value in SELECT type input, provide manually.
Experiment :
To show my logic on how to do this, i tried this code
// $query2['via'] will produce fetched value from database
<select selected='".$query2['via']."' name='slPayment'>
<option>--</option>
<option value='Cash'>Cash</option>
<option value='Bank Transfer'>Bank Transfer</option>
<option value='Credit Card'>Credit Card</option>
<option value='Cheque'>Cheque</option>
<option value='Others'>Others</option>
</select>
Experiment Result :
Wont Work
Desired Output :
I actually just want that SELECT type input, show the exactly same value from fetched database value. Any idea how to fix this ?
Thank You
Thank you for Stackoverflow community. I won't stop saying thank you. Btw, i purely asking for learning and knowledge sharing. I'm open to any comment (related info with this question).
But please don't judge me like i am just asking for code. I actually learn how to code based on that code itself, then i adapt to make use of that code properly, am not familiar with library, am still a college student. I wont ask before i try it by myself. Some people did judge me on recent question. And it's not very nice act to this community. I'm learning, we learning.
So thank you once again.
You can change your code thus:
<select name='slPayment'>
<option>--</option>
<option " . (($query2['via']=='Cash') ? 'selected="selected"': '') . "value='Cash'>Cash</option>
<option " . (($query2['via']=='Bank Transfer') ? 'selected="selected"': '') . " value='Bank Transfer'>Bank Transfer</option>
<option " . (($query2['via']=='Credit Card') ? 'selected="selected"': '') . " value='Credit Card'>Credit Card</option>
<option " . (($query2['via']=='Cheque') ? 'selected="selected"': '') . " value='Cheque'>Cheque</option>
<option " . (($query2['via']=='Others') ? 'selected="selected"': '') . " value='Others'>Others</option>
</select>
这篇关于根据数据库提取值设置选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!