Editing/Updating one of the results in a search query.

Posted by eggman20 on Stack Overflow See other posts from Stack Overflow or by eggman20
Published on 2011-01-06T11:41:18Z Indexed on 2011/01/06 11:54 UTC
Read the original article Hit count: 289

Filed under:
|
|

Hi guys.

I'm creating a page that searches for an item and then be able to edit/update it. I was able to do it when it returns just one result but when it gives me multiple results I could only edit the very last item. Below is my code:

.......
$dj =$_POST[djnum];
$sql= "SELECT * From dj WHERE datajack LIKE '$dj%'";
$result = mysql_query($sql);
    //more code in here//

while ($info =mysql_fetch_array($result)) {

    // display the result
echo "<form action=\"dj_update.php\" method=\"POST\"><input type=\"hidden\" name=\"djnumber\" value=\"".$info['datajack']."\">";
echo "<tr><td>DJ ".$info['datajack']."</td>";
echo "<td>".$info['building']."&nbsp;</td>";
echo "<td>Rm ".$info['room']."&nbsp;</td>";
echo "<td>".$info['switch']."&nbsp;</td>";
echo "<td>".$info['port']."&nbsp;</td>";
echo "<td>".$info['notes']."&nbsp;</td>";
echo "<td style=\"text-align:center;\"><input type=\"Submit\" value=\"Edit\" ></td></tr>";      
}

// more code here //

Then this is the screen shot of the result:

alt text

The idea is the user should be able to click on "Edit" and be able to edit/update that particular item. But when I click any of the Edit button I could only edit the last item. What am I missing here? Is there an easier way to do this?

Thanks guys and Happy new year!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql