I am wondering if this is possible:

I have a web page that displays a table which includes Work Order Numbers. I would like to make the numbers into a link that when I click it it automatically brings up an edit form for that particular record. For example, here is some code for the table:

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['WO'] . "</td>";
  echo "<td>" . $row['Customer'] . "</td>";
  echo "<td>" . $row['Status'] . "</td>";
  echo "<td align=\"center\">" . $row['Entered'] . "</td>";
  echo "<td>" . $row['Description'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

Now, in the echo "<td>" . $row . "</td>"; line I would like something like:
echo "<td><a> " . $row . " </a></td>";
so that if I click the WO number it will search for that particular record and bring up a form where I can edit it. I just have no idea what code to put within the <a></a> tags to make this possible or if it is even possible. Another way that might work for me would be to put an edit button in each row.

If your question is on whether if it is possible, then yes.

but how to go about achieving that I think there are many ways.

pop-up? form appear in a div below? can be achieved one way or another..

google edit button for each row php

I should have posted my solution when I got it figured out. Here is what I did:

I used headers like this so I could sort by different columns
echo "<table border='1' rules='rows'>
<tr>
<th><a href=\"viewTable.php?id=".WO."\" >WO</a></th>
<th><a href=\"viewTable.php?id=".Customer."\" >Customer</a></th>
<th><a href=\"viewTable.php?id=".Status."\" >Status</a></th>
<th><a href=\"viewTable.php?id=".Description."\" >Description</a></th>
<th><a href=\"viewTable.php?id=".Date."\" >Date</a></th>
</tr>";

This is how I created the links
while($row = mysql_fetch_array($result))
  {
  $d=$row['Date'];
  $cnt=$cnt+1;
  if (is_int($cnt/2))
  {
    $bg="#EBEBEB";
  }else
  { $bg="white";}
  echo "<tr bgcolor=\"".$bg."\">";
  echo "<td>" . "<a href=\"form1.php?id=".$row['WO']."\" >".$row['WO'] . "</a></td>";
  echo "<td>" . "   ".$row['Customer'] . "</td>";
  echo "<td>" . "   ".$row['Status'] . $row['Proof'] . "</td>";
  echo "<td>" . "   ".$row['Description'] . "</td>";
  echo "<td>" . "   ".substr($d,0,10) . "</td>";
  echo "</tr>";}
echo "</table>";

This sends the work order number to form1.php. The syntax could be improved, especially with quotes. This works but it doesn't look very tidy.

The $bg creates a different color for each row which makes the table easier to read.

how does the form1.php look like?

This is form1.php:

<?php
$con = mysql_connect("***.com","***","***");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

If the work order is not found it automatically creates a new record with that number
mysql_select_db("***", $con);
$search=$_POST['search'];
if($search==""){$search=$_REQUEST['id'];}

$d=date("Y-m-d H:i:s");
$sql="INSERT INTO IP (WO, Customer, Description, Status, Entered, Date)VALUES('$search','','','','','$d')";

otherwise it pulls up the existing record
mysql_query($sql,$con);
$data = 'SELECT * FROM IP WHERE WO = "'.$search.'"'; 
  $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error()); 
  $data2 = mysql_fetch_array($query); 

 
   
?> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
      <title></title> 
<link rel="stylesheet" href="ip.css" />
<script type="text/javascript" language="javascript">

    function redirect()
    {
        // you can also pass the complete URL of location
        // e.g.: http://www.google.com/ or
        // http://programming.top54u.com/Default.aspx
        
        location.replace("viewTable.php?id=WO");
    }

    </script>
</head> 

<body> 

<!-- form to display record from database --> 
<form name="form" method="POST" action="form2.php" target="hidden"> 
<table align="center">
<tr>
<td align="right">WO:</td><td><input type="text" name="WO" value="<?php echo $search?>" size=30" height="50"/></td>
</tr>
<tr>
<td align="right">Customer:</td><td><input type="text" name="Customer" value="<?php echo $data2[Customer]?>" size="30"/></td>
</tr>
<tr>
<td align="right">Description:</td><td><input type="text" name="Description" value="<?php echo $data2[Description]?>" size="30"/></td>
</tr>
</table>
<table align="center" cellpadding="8" border="0">
	<tr>
	<td width="100" height="25">Status:</td>
	<td width="100"height="25" align="right">Proof: <input name="Proof" id="Proof" type="checkbox" value="|Proof" <?php if($data2['Proof'] == "|Proof"){echo 'checked="checked"';}?> /></td>
	</tr>



... a lot of radio buttons here for the status of the job... I have since changed my system of entry but if I would have continued with this system I would have rather used a drop down list.



</table>
<table align="center" border="0">
        <tr>
	<td width="100%" height="25" align="center"><input type="submit" style="height: 40px; width: 200px" value=" submit " /></td>
	</tr>
        <tr>
	<td width="100%" height="25" align="center"><input type="button" value="Return to Tableview" style="height: 40px; width: 200px" onclick="redirect();" /></td>
	</tr>
</table>
</form>


</body> 

</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.