2011-08-09 79 views
0

這裏我試圖從MySQL表中獲取數據並將其填充到html中。一切工作正常但我想通過IF條件呼應HTML按鈕。我不知道這是否可以工作..如果它工作...任何人都可以請告訴我如何使它工作?錯誤時得到的是...內部服務器錯誤:(HTML和PHP嵌入

注:我已經commeted在那裏我有問題

<?php 
if(mysql_num_rows($sql)){ 
    while($rs = mysql_fetch_object($sql)) 
    { 
    ?> 
     <tr> 
      <td align="center"><?php echo $rs->cnf_name ;?></td> 
      <td align="center"><?php echo $rs->address;?></td> 
      <td align="center"><?php echo $rs->added_on;?></td> 
      <td align="center"><input type="button" class="btn" value="Edit" onClick="window.parent.editCnf('<?php echo $rs->cnf_name;?>','<?php echo $rs->username ;?>','<?php echo $rs->password;?>','<?php $rs->type;?>','<?php echo $rs->person_name;?>','<?php echo $rs->address;?>','<?php echo $rs->mobile_no?>','<?php echo $rs->email;?>','<?php echo $rs->country;?>','<?php echo $rs->city;?>','<?php echo $rs->state;?>','<?php echo $rs->area;?>')" ></td> 




//PROBLEM 


      <td align="center"> 

      <?php 
      if($rs->cnf_status == 0) 
      { 
      echo "<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf(<?php echo $rs->user_id;?>,<?php echo $rs->cnf_status; ?>);">"; 
      } 
      else 
      { 
      echo "<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf(<?php echo $rs->user_id;?>,<?php echo $rs->cnf_status; ?>);">"; 

      } 
?>   




      </td> 
     </tr> 
<?php 
    } 
} 
else 
{ 
?>  <tr> 
      <td colspan="">No data to display</td> 
     </tr> 
<?php 
} 
?>  
    </tbody> 
</table> 

回答

0

的問題是在你的語法,你必須逃離「的確切地點你回聲:

<?php 
    if($rs->cnf_status == 0) 
     { 
     echo "<input type=\"button\" class=\"btn\" id=\"status\" value=\"Activate\" onClick=\"window.parent.deleteCnf({$rs->user_id}, {$rs->cnf_status});\">"; 
     } 
    else 
     { 
     echo "<input type=\"button\" class=\"btn\" id=\"status\" value=\"Activate\" onClick=\"window.parent.deleteCnf({$rs->user_id}, {$rs->cnf_status});\">"; 
     } 
?>   

OR

<?php 
    if($rs->cnf_status == 0) 
     { 
     echo '<input type="button" class="btn" id="status" value="Activate" onclick="window.parent.deleteCnf(' . $rs->user_id . ', ' . $rs->cnf_status . ');">'; 
     } 
    else 
     { 
     echo '<input type="button" class="btn" id="status" value="Activate" onclick="window.parent.deleteCnf(' . $rs->user_id . ', ' . $rs->cnf_status . ');">'; 
     } 
?>   
3

問題來自於你與回聲使用引號; 要麼去

echo 'htmlcode_with_doublequotes'; 

if($rs->cnf_status == 0) 
{ 
?> 
     <input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf("<?php echo $rs->user_id;?>","<?php echo $rs->cnf_status; ?>");"> 
<?php 
} 
else 
{ 
?> 
     <input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf("<?php echo $rs->user_id;?>","<?php echo $rs->cnf_status; ?>");"> 
<?php 
} 
1

這只是似乎是在按鈕的HTML的回聲引號中的問題。

if($rs->cnf_status == 0) 
     { 
     echo '<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf(<?php echo $rs->user_id;?>,<?php echo $rs->cnf_status; ?>);">'; 
     } 
     else 
     { 
     echo '<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf(<?php echo $rs->user_id;?>,<?php echo $rs->cnf_status; ?>);">'; 

     } 
0

試試這個:

<?php 
if($rs->cnf_status == 0) 
{ 
echo '<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf('.$rs->user_id.','.$rs->cnf_status.');">'; 
} 
else 
{ 
echo '<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf('.$rs->user_id.','.$rs->cnf_status.');">'; 

} 
?>