我在尝试显示所选项目数组时遇到问题。我的意思是,我有一个列表,显示一个ID,名称,Apellido的表。 (名称是带有dinamic数组的那个[]。
当我把桌子翻转好的时候,但是当我点击编辑按钮时,我得到了正确的id,右边的apellido和名字得到了最后插入的数组。
如果我点击编辑身份证号码5,我有15,它会显示15而不是数字5(所选的)。
有人能找到我做错的事吗?
感谢
这是使用
的文件list.php
update.php
<!DOCTYPE html>
<?php
$host="localhost"; // Host name
$username="inputmultiplicad"; // Mysql username
$password="inputmultiplicado"; // Mysql password
$db_name="inputmultiplicado"; // Database name
$tbl_name="input_field"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$id=$_GET['id'];
$first_name=$_GET['first_name'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
// Retrieve data from database to implode/explode
$select_tbl=mysql_query("select * from input_field");
while($fetch=mysql_fetch_object($select_tbl))
{
echo $id;
$r=$fetch->firstname;
$i=explode(",",$r);
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/estilos.css" media="screen" />
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Oxygen' rel='stylesheet' type='text/css'>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="main contenedor">
<header>
<section class="logo">LOGO</section> <!--logo-->
</header>
<div id="contenedor">
<div class="insertar_formulario">
<h3>Editar Cliente</h3>
<h3>id</h3>
<? echo $rows['id'];
?>
<form name="form1" method="post" action="update_ac.php">
<section class="nombre"><h2>Nombre</h2>
<?
for($x = 0; $x < count($i); $x++ )
{
echo "<input type='text' name='firstname[]' value='$i[$x]'><input type='button' value='+'/><br />";
};
?>
</section>
<section class="apellido"><h2>Apellido</h2>
<input type='text' name='apellido[]' value='<? echo $rows['apellido']; ?>'/>
</section>
<section class="enviar">
<input type="submit" name="Submit" value="Submit">
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</section>
</form>
</div>
</div><!--contenedor-->
</div> <!--main contenedor-->
</body>
</html>
<?php
// close connection
mysql_close();
?>
list.php的
<?php
$host="localhost"; // Host name
$username="inputmultiplicad"; // Mysql username
$password="inputmultiplicado"; // Mysql password
$db_name="inputmultiplicado"; // Database name
$tbl_name="input_field"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>
<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong><a href="agregar_cliente.php">Add+</a></strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['id']; ?></td>
<td><? echo $rows['firstname']; ?></td>
<td align="center"><a href="ver_update.php?id=<? echo $rows['id']; ?>">Editar</a></td>
<td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>
答案 0 :(得分:0)
解决,这是一个愚蠢的事情
更改update.php
这样:
$select_tbl=mysql_query("select * from input_field");
为:
$select_tbl=mysql_query("select * from input_field WHERE id='$id'");