简体   繁体   English

使用onclick调用分配php变量始终分配第二个onclick

[英]using onclick to call assign a php variable always assigns the second onclick

I have these onclicks that when clicked changes the value of $table which has been instantiated in the head $table = 'dust_devils'; 我有这些onclicks,单击时会更改$ table的值,该值已在头部$table = 'dust_devils';实例化$table = 'dust_devils'; to the default of dust_devils 到默认的dust_devils

<span onclick = <?php $table = 'dust_devils';?>> Dust Devils </span> <br />
<span onclick = <?php $table = 'fire_giants';?>> Fire Giants </span>

these connect to my function function getLog($table){...} in order to get a specific table from my database. 这些连接到我的函数function getLog($table){...} ,以便从数据库中获取特定的表。

However when my page loads it automatically loads to the last assignment. 但是,当我的页面加载时,它会自动加载到最后一个作业。 In this case it's fire_giants. 在这种情况下,它是fire_giants。

Anyone know what's wrong here? 有人知道这是怎么回事吗?


EDIT: Besides the fact that serverside + client side doesnt interact. 编辑:除了服务器端+客户端不会交互的事实。 There is a default value that it isn't following declared SERVER side. 有一个默认值,它不遵循声明的SERVER端。

You'd have to do something like this. 您必须做这样的事情。

<span onClick = "load('FireGiants')">Fire Giants</span>

With Jquery/javascript whatever 使用Jquery / javascript可以

<script>
function load(type){
  $.AJAX({
      Method:"post",
      url:"getTable.php",
      data : {"type" : type},
      success : function(d) {
          $('#AREATOAPPEND').append(d);
      }
  });

}
</script>

With a php page that just does the rendering for the click function. 用一个php页面,它只是为click函数渲染。

 <?php
 $type = $_POST['type'];

 //Do Table Generation

 echo 'Table for this type';
 ?>

Or you could just pass the entire structure to the table via JSON or something and render it client side on the fly. 或者,您可以通过JSON或其他方式将整个结构传递给表,然后将其动态呈现给客户端。

You are forgetting that all of the PHP is evaluated and executed on the server, before the page is sent to the browser. 您会忘记在将页面发送到浏览器之前,已在服务器上评估并执行了所有PHP。

If you view the HTML source in your browser (normally by pressing Ctrl+U), you will see what I'm talking about. 如果您在浏览器中查看HTML源代码(通常通过按Ctrl + U),您将看到我在说什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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