为啥所有按钮只控制同一行数据?应该怎么解决啊。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><script language="javascript" type="text/javascript"> function showtd(num) { document.getElementById("bg"+num).style.display = "none"; document.getElementById("show"+num).style.display = "block"; document.getElementById("ba"+num); document.getElementById("gn"+num); } function hidetd(num) { document.getElementById("bg"+num).style.display = 'block'; document.getElementById("show"+num).style.display = 'none'; } function showtext(){ document.getElementById("a").removeAttribute("readOnly"); document.getElementById("b").removeAttribute("readOnly"); document.getElementById("c").removeAttribute("readOnly"); document.getElementById("d").removeAttribute("readOnly"); document.getElementById("e").removeAttribute("readOnly"); document.getElementById("f").removeAttribute("readOnly"); } function hidetext(){ document.getElementById("a").readOnly="true"; document.getElementById("b").readOnly="true"; document.getElementById("c").readOnly="true"; document.getElementById("d").readOnly="true"; document.getElementById("e").readOnly="true"; document.getElementById("f").readOnly="true"; } </script></head><body> <form> <table border="1"> <?php $db = mysql_connect('localhost','root','root'); mysql_select_db('ec',$db); if (!$db) { die('Could not connect: ' . mysql_error()); } $result = mysql_query("select * from goods"); echo "<tr> <th>GoodsID</th> <th>BarCode</th> <th>GoodsName</th> <th>Category</th> <th>Specifications</th> <th>Manufacturers</th> <th>Numbers</th> <th>Instructions</th> <th>Pictures</th> <th>Update</th> <th>Delete</th> </tr>"; $n = 0; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . "<input type='text' id='a' value='$row[barcode]' style='width:60px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<input type='text' id='b' value='$row[goods_name]' style='width:90px;border:0px' readOnly>" . "</td>"; echo "<td>" . $row['category'] . "</td>"; echo "<td>" . "<input type='text' id='c' value='$row[specifications]' style='width:90px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<input type='text' id='d' value='$row[manufacturers]' style='width:90px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<input type='text' id='e' value='$row[number]' style='width:60px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<input type='text' id='f' value='$row[instruction]' style='width:80px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<img src = '$row[picture_url]' style="max-width:90%"/ alt="为啥所有按钮只控制同一行数据?" >" . "</td>"; echo "<td id='bg$n'>". "<input id='btnshow$n' type='button' value='Update' onclick='showtd($n);showtext()' />". "</td>". "<td id='show$n' style='display:none'>". "<input id='btnclose$n' type='button' value='Save' onclick='hidetd($n);hidetext()'/>". "</td>"; echo "<td>"."<a href='delete.php?id=$row[id]'>"."Delete"."</a>"."</td>"; echo "</tr>"; ++$n; } mysql_close($db);?> </table></form></body></html>
回复讨论(解决方案)
总觉得你这代码有一堆语法问题啊
总觉得你这代码有一堆语法问题啊
可以正常运行。
循环输出有多少个id='a'呢?
然后 document.getElementById("a") 会得到什么……
什么情况?数据库读出来ID都对的吧?这个应该id有传过去吧,再试试吧~
循环输出有多少个id='a'呢?
然后 document.getElementById("a") 会得到什么……
我也觉得是这个id的问题,就是不知道怎么改。
什么情况?数据库读出来ID都对的吧?这个应该id有传过去吧,再试试吧~
a标签读出来的id是我在数据库内设置的主键,和d的id是两码事。
引用 1 楼 chendong_j 的回复:
总觉得你这代码有一堆语法问题啊
可以正常运行。
顿时感觉lz好强大
你每行同一列的 id 都相同,怎么能用 getElementById 来定位呢?
65-71行 设置的id都是重复的 如果区分的话可以把设置的ID(a,b,c...)前拼接上$row['id']加以区分

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
