Jump to content

Having Problem with $_get in Codeigniter


srijon

Recommended Posts

I have a page called list.php which retrieves from database and shows all the student names with their respective ids in a list. In raw php, this is how I have done this-

 

include("connect.php");

$query = "SELECT * FROM marks ";

$result = mysql_query($query);

$num = mysql_num_rows ($result);

mysql_close();

if ($num > 0 ) {

$i=0;

while ($i < $num) {

$studentname = mysql_result($result,$i,"studentname");

$studentid = mysql_result($result,$i,"studentid"); 

?>

And then---

 

<a href="studentprofile.php?studentid=<? echo $studentid?>"><? echo $studentname ?></a>

<?

++$i; } } else { echo "No Record Found"; }

?>

 

When a user clicks on any of the student names, it takes the user to the page of that particular student and in that page I have a code like following-

 

include("connect.php");

$number = $_GET['studentid'];

$qP = "SELECT * FROM student WHERE studentid = '$number' ";

$rsP = mysql_query($qP);

$row = mysql_fetch_array($rsP);

extract($row);

$studentid = trim($studentid);

$studentname = trim($studentname);

$studentgender = trim($studentgender);

 

The above code is working just fine. Now as far as I know $_get is disable in Codeigniter. But how to do the exact same thing that I mentioned above in codeigniter if $_get is disabled ? I went through some tutorials on alternative way of using $_get, but I didn't understand those well. Would you please kindly help? Thanks in Advance :)

codeigniter

 

 

Link to comment
https://forums.phpfreaks.com/topic/245185-having-problem-with-_get-in-codeigniter/
Share on other sites

The URL would look like:

 

index.php/student/get/1

 

get in the URL has nothing to do with the variable. And you would access it like:

 

class Student extends Controller
{
  public function get($id)
  {
    $this->load->model('studentmodel');
    $student = $this->studentmodel->find($id);
    
    $this->load->view('student/info', array('student' => $student));
  }
}

 

This is how CI works.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.