0

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.

2 Answers 2

1

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>";
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your answer. I tried exactly like you said, but no luck. The only thing i want from this is to change a value in my database table "logg" from "0" to "1" and that is is done by a single click on the link. Any sugestion on the easiest way to do this?
Does the do.php page work correctly if you pass it the command and id directly? If so, there's an issue with the javascript. If do.php doesn't work right with that, you'll have to figure that one out separately.
1
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>";

8 Comments

Hi, this did not work for me, and i tried another solution from the other answer i got here and that did not work either. Any suggestions?
No, i do not get any error, the link is displayed as it should, but when i click the link it does not update the value to the database.
So the source code shows the link as being generated properly? Is the click event being triggered? Are you debugging the jQuery with firebug or Chrome's dev tools to see if the .get() request is failing?
i tried to fill in some of the source code her, but the text is'nt displayed as code.... But the source code seems to be generating the link. i'm sorry, but debugging is something i'm not too familiar with how to do.
'<td>2012-06-12 20:34:55</td><td>Tore Skjelvan</td><td>Hghkgt</td><td><a href="javascript:void(0);" onclick="$.get("doeventedit.php",{ cmd: "ban", id: } ,function(data){ $("#ban").html(data);});">Ban</a> </td></tr><tr><td>2012-06-12 18:29:46</td><td>Tore Skjelvan</td><td>Halla</td><td><a href="javascript:void(0);" onclick="$.get("doeventedit.php",{ cmd: "ban", id: } ,function(data){ $("#ban").html(data);});">Ban</a>'
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.