如何通过数据库来实现对应数据的输出(描述的可能有点问题,内详)?
现在的代码,已在最后附上。我想添加办公室名称的话,直接用insert into进officename那个表就可以了
但是,这里officename与officecode是通过JS写死了。如果这样添加的话,两者的对应就有问题了,新添加的数据,是没有对应的officecode的,这就需要手动在js代码里添加,感觉这样很不合理。
所以我想的是不通过js,而是直接从数据库读取,officename表中共建立两个字段name与code
直接通过读取数据库,将两者来进行对应,这样是否可行。需要怎样操作,最好有实例,谢谢
<br /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><br /> <br /> <head><br /> <script language="javaScript"><br /> function setofficecode()<br /> {<br /> //获取officename/officecode的值<br /> var officename = document.getElementById("officename").value;<br /> var o = document.getElementById("officecode");<br /> //条件判断<br /> if(officename == "XX办公室"){<br /> o.value="101";<br /> }<br /> else if(officename == "YY办公室"){<br /> o.value="201";<br /> }<br /> else if(officename == "ZZ办公室"){<br /> o.value="301";<br /> }<br /> <br /> }<br /> </script><br /> </head><br /> <br /> <br /> <form action="study3.php" method="post"><br /> <div align="center"><br /> <table><br /> <tr><br /> <td>办公室名称</td><br /> <td><br /> <select name="officename" id="officename" onchange="setofficecode()" style="width:150px;"><br /> <?php<br /> include('conn.php');<br /> $sql="select * from officename";<br /> $query=mysql_query($sql);<br /> while($result=mysql_fetch_array($query)){<br /> ?><br /> <option value="<?=$result[officename]?>"><?=$result[officename]?></option><br /> <?php<br /> }<br /> ?><br /> </select><br /> </td><br /> </tr><br /> <tr><br /> <td>办公室号码</td><br /> <td><input type="text" name="officecode" id="officecode" style="width:150px;" value="101" /></td><br /> </tr><br /> </table><br /> <br /> <input type="submit" value="提交" /><br /> </div><br /> <br /> <br /> </form><br />
------解决方案--------------------
改好了
<meta><br> <br> <br> <br> <br> <br>

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

你应该关心DependencyInjection(DI),因为它能让你的代码更清晰、更易维护。1)DI通过解耦类,使其更模块化,2)提高了测试的便捷性和代码的灵活性,3)使用DI容器可以管理复杂的依赖关系,但要注意性能影响和循环依赖问题,4)最佳实践是依赖于抽象接口,实现松散耦合。

是的,优化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)优化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,并避免使用

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,3)配置

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

SublimeText3 Linux新版
SublimeText3 Linux最新版

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中