Jump to content

not showing select array


unasemana
Go to solution Solved by unasemana,

Recommended Posts

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();
?>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Solution

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 by unasemana
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.