如何在PHP代码中使用带有html标签的引号

时间:2012-02-04 18:13:32

标签: php javascript html

嗨我想在php中使用html代码而在每个循环中生成html代码的命令但我不知道如何在php代码中使用引号将真值发送到java脚本!
这是我在php中的代码

<?php
include 'Connect.php'; 
if(match($_POST['pId'], "/^[\d]+$/") ){
$pId = $_POST['pId'];
$result = mysql_query("select pName, pID, phName, phID, testHistoryDate, type, testAnswer from patient join reception using(pID) join physician using(phID) join testHistory using(rID) join test using(tID) where pID = $pId",$connection);
}
else
die("Insert true value");
while($row=mysql_fetch_array($result)){
echo "<tr><td>";
echo $row["pName"].'</td>';
echo '<td>'.$row["phName"].'</td>';
echo '<td>'.$row["testHistoryDate"].'</td>';
echo '<td>'.$row["type"].'</td>';
$type =  $row['type'];
$testHistoryDate = $row['testHistoryDate'];
?>
<td>
<span id='spryTanswer'>
<input type='text' name='tAnswer' id='tAnswer' value='<?php echo $row['testAnswer']; ?>' />
</span>
</td>
<td>
<input type='submit' value='Edit' name='edit' id='edit' onclick="sendToEdit('<?php echo $row['pID'] ?>','<?php echo $row['phID'] ?>', '<?php echo $row['testHistoryDate'] ?>', '<?php echo $row['type'] ?>')" />
</td>
</tr>
<?php } ?>

获取这些值并将主题发送到另一个PHP代码的java脚本代码。

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function sendToEdit(pID,phID,thDate,type) 
{
testAnswer = $("#tAnswer").blur().val();
testAnswer = $("#tAnswer").change().val();
var info = 'pId='+pID+'&phId='+phID+'&testAnswer='+testAnswer+'&thDate='+thDate+'&type='+type;
$.ajax({
type:"GET",
url:"edit-testAnswer.php",
data:info,
success:function(){
}
});
return false;
}
</script>

3 个答案:

答案 0 :(得分:2)

我不明白你的意思&#34;真实的引语&#34;或者&#34;真正的价值&#34;,但是在PHP字符串中渲染所有HTML就像这样在一开始就没有任何意义:

<tr>
  <td>
    <span id='spryTanswer'>
      <input type='text' name='tAnswer' id='tAnswer' value='<?php echo $row['testAnswer']; ?>' />
    </span>
  </td>
  <td>
    <input type='submit' value='Edit' name='edit' id='edit' onclick='<?php echo sendToEdit($row['pID'], $testHistoryDate, $type); ?>' />
  </td>
</tr>

答案 1 :(得分:1)

这就是我写你提供的代码的方式....

include 'Connect.php'; 
if(match($_POST['pId'], "/^[\d]+$/") )
{
  $pId = $_POST['pId'];
  $result = mysql_query("select pName, pID, phName, phID, testHistoryDate, type, testAnswer from patient join reception using(pID) join physician using(phID) join testHistory using(rID) join test using(tID) where pID = $pId",$connection);
}
else die("Insert true value");

while($row=mysql_fetch_array($result)): ?>
  <form onSubmit="return false;">
    <input type="hidden" name="pId" ="<?php echo $row['pID']; ?>" />
    <input type="hidden" name="phId" ="<?php echo $row['phID']; ?>" />
    <input type="hidden" name="thDate" ="<?php echo $row['testHistoryData']; ?>" />
    <input type="hidden" name="type" ="<?php echo $row['type']; ?>" />
  <tr>
    <td><?php echo $row['pName']; ?></td>
    <td><?php echo $row['phName']; ?></td>
    <td><?php echo $row['testHistoryData']; ?></td>
    <td><?php echo $row['type']; ?></td>
    <td>
      <span id='spryTanswer'>
      <input type='text' name='tAnswer' id='tAnswer' value='<?php echo $row['testAnswer']; ?>' />
      </span>
    </td>
    <td>
      <input type='button' value='Edit' name='edit' id='edit' onclick="sendToEdit(this.form)" />
    </td>
  </tr>
  </form>
     

    function sendToEdit(thisForm)     {       $就({         键入: “GET”,         网址:“编辑testAnswer.php”         data:thisForm.serialize(),         成功:函数(){         }         });       返回false;     }

答案 2 :(得分:0)

在引号前加上反斜杠,'<span onclick="alert(\'Do something\');">'