简体   繁体   中英

How to write a link within a php/html form

I want to input som text to generate an update link in a form field, but since the fields are populated from a sql database and is within php section of the code i need help to figure out how to write the link correctly.

the link is:

<a href="javascript:void(0);" onclick='$.get("do.php",{ cmd: "ban", id: "<?php echo $rrows['id']; ?>" } ,function(data){ $("#ban<?php echo $rrows['id']; ?>").html(data); });'>Ban</a>

And this is the section where i want the link placed, marked my_link:

$result = mysql_query("SELECT * FROM logg WHERE UserGroup='".$_SESSION['user_group']."'     AND CompletedEvent='0'  ORDER BY RegDate DESC");

echo "<table border='1'>
<tr>
<th>RegDate</th>
<th>RegByUser</th>
<th>Event</th>
<th>Status</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['RegDate'] . "</td>";
  echo "<td>" . $row['RegByUser'] . "</td>";
  echo "<td>" . $row['Event'] . "</td>";
  echo "<td>" my_link "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

I hope someone can show the the right way to write this link.

Put the following in the header:

<script type="text/javascript">
    function banUser(id)
    {
        $.get("do.php",{cmd: "ban",id: id}, 
            function(data){$("#ban"+id).html(data);}
        );
    }
</script>

Then use this in your while loop:

echo "<td><a href='#' onclick='banUser(\"" .
     $row['id'] . 
    "\");'>Ban</a></td>";
echo "<td><a href=\"javascript:void(0);\" onclick=\"$.get('do.php',{cmd:'ban',id:'" . $rrows['id'] . "'},function(data){\$('#ban" . $rrows['id'] . "').html(data);});\">Ban</a>my_link \"</td>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM