weixin_33716941 2015-08-14 12:23 采纳率: 0%
浏览 46

简单的PHP到Codeigniter

i am developing my final year project on codeigniter and facing problem i want to click a drop-down value and then it will return table from db but alas i can't do

this is plain php code that i want to convert into codeigniter please help me thanks in advance.

<!DOCTYPE html>
<html>
<head>
<script>
function showUser(str) {
  if (str=="") {
    document.getElementById("txtHint").innerHTML="";
    return;
  } 
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","getuser.php?q="+str,true);
  xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Joseph Swanson</option>
<option value="4">Glenn Quagmire</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>
  • 写回答

2条回答 默认 最新

  • 叼花硬汉 2015-08-14 12:35
    关注

    You need to separate the code in Controller, View and Model:

    • Model for DDBB operations.

    • Controller: control where the data goes and how it can be displayed, and other logic.

    • View, here is where the form is rendered.

    Codeigniter has a great documentation to learn how to do it.

    Controllers

    Views

    Models has the same url, but for models, i've not reputation enough to post 3 links, sorry

    评论

报告相同问题?