Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.