unasemana Posted March 15, 2014 Share Posted March 15, 2014 Hi, im having problems trying to show the selected items array. I mean, i have a list that shows a table with ID, Name,Apellido. (name is the one with dinamic array []. When i se the table everthing is allright, but when i click the edit button, i get right id, the right apellido and name gets the last array inserted. If i click to edit ID number 5 and i have 15, it will show me the 15 instead of number 5 (the selected one). could anyone find what im doing wrong? thanks this are the files im using 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(); ?> and 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/287000-not-showing-select-array/ Share on other sites More sharing options...
Ch0cu3r Posted March 15, 2014 Share Posted March 15, 2014 Your post does not make sense. Can you explain what the two codes should be doing. Quote Link to comment https://forums.phpfreaks.com/topic/287000-not-showing-select-array/#findComment-1472734 Share on other sites More sharing options...
unasemana Posted March 15, 2014 Author Share Posted March 15, 2014 the file list.php shows the content of the table, is a table that shows a list of ID, names, and secondnames, that list in every line has a EDIT button and a delete button. When you click Edit it will take you to update.php, this file shows the selected ID, an input field type text with the selected apellido and if you want to chage it you change it. But firstname is an array[] that is created with jquery so people could insert more than one. this field should show the exact names but it shows the last on the table and not the selected. Thats the problem im having. the other fields are shown correctly. excuse my english Quote Link to comment https://forums.phpfreaks.com/topic/287000-not-showing-select-array/#findComment-1472744 Share on other sites More sharing options...
Solution unasemana Posted March 16, 2014 Author Solution Share Posted March 16, 2014 (edited) just solve it, it was something really stupid jus change this line in the update.php $select_tbl=mysql_query("select * from input_field"); to: $select_tbl=mysql_query("select * from input_field WHERE id='$id'"); Edited March 16, 2014 by unasemana Quote Link to comment https://forums.phpfreaks.com/topic/287000-not-showing-select-array/#findComment-1472755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.