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 🙂
The usage of
$_GETis discouraged in CI.The simpliest way to rewrite that files is not using
$_GET. Just addmethod='post'to your forms and tell your ajax requests to use post, if you have any. Use$_POSTin PHP instead of$_GET.If you are absolutely sure you need get requests passing parameters, you have to enable
query strings. You can do it in your CI’s config file:See section ‘Enabling query strings’ for details. But enabling
query stringswill causeUrl helperand other helpers that generate URLs to malfunction.So my suggestion is to use POST requests.
UPDATE Replace
With
Create method
studentprofile: