Welcome Guest, Not a member yet? Register   Sign In
SOLVED::I WANT TO DISPLAY THE COURSE NAME
#1

[eluser]charlesmudy[/eluser]
Hi,

I'm new to CodeIgniter.

My question is, I would like to view the name of my course_id which is in another table but it simply gives me the details from that table.

I have a table called student which has the ID of the courses table, so when I select the row from the student table..it gives me ofcourse the row id but I want the course name to be displayed.

My code:

&lt;?php echo "Status: " . " " . $row->status_id; ?&gt;<br />
&lt;?php echo "Course: " . " " . $row->course_id; ?&gt;<br />
&lt;?php echo "Nationality: " . " " . $row->nationality_id; ?&gt;

My display:Attached


Thanks in advance.

Charles
#2

[eluser]ηυмвєяσηє[/eluser]
please fix the title, Its so ugly.

About your problem, you should change your sql query. Something like this :

$query = "SELECT student.first_name, student.last_name, student.status_id, student.nationality_id, courses.name FROM student, courses WHERE student.course_id = courses.id";
#3

[eluser]InsiteFX[/eluser]
I guess that when you clicked on FAST REPLY you did not read the BIG RED LETTERS!
InsiteFX
#4

[eluser]dUspan[/eluser]
yes

try using LEFT JOIN.it will helps you display what you need.
Code:
$this->query("SELECT * FROM table1 LEFT JOIN table1 ON table1.id = table2.id where id = ?");

i just the used (*) for example purposed only.its much better when you select only the row you want to display.

i hope it helps Big Grin
#5

[eluser]charlesmudy[/eluser]
[quote author="ηυмвєяσηє" date="1306416823"]please fix the title, Its so ugly.

About your problem, you should change your sql query. Something like this :
Code:
$q = "SELECT student.first_name, student.last_name, student.status_id, student.nationality_id, courses.name FROM student, courses WHERE student.course_id = courses.id"
[/quote]

I tried it but still not working.

My controller:

Quote:public function get_student()
{
$id = $this->uri->segment(3);
$data['query'] = $this->db->query("SELECT firstname, lastname, status_id, nationality_id, course_name FROM students, courses WHERE course_id = courses.id");
$this->load->view('student_view', $data);
//echo site_url("http://localhost/database/index.php/students/student_view");
}

My view:
Quote:&lt;?php echo "Course: " . " " . $row->course_id; ?&gt;<br />
&lt;?php echo "Nationality: " . " " . $row->nationality_id; ?&gt;


Error message:
Quote:Personal Data Information for John

First-name: John
Last-name: Baptise
Status: 0
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$course_id

Filename: views/student_view.php

Line Number: 11

Course:
Nationality: 3
#6

[eluser]charlesmudy[/eluser]
[quote author="ηυмвєяσηє" date="1306416823"]please fix the title, Its so ugly.

About your problem, you should change your sql query. Something like this :

$query = "SELECT student.first_name, student.last_name, student.status_id, student.nationality_id, courses.name FROM student, courses WHERE student.course_id = courses.id";[/quote]

Ohh sorry I didnt change the course_id ...to course_name

Now I got it...thank you so much after 2 nights of sweat

woooooooooooooooooooooooooo..now I get
Quote:Personal Data Information for John

First-name: John
Last-name: Baptise
Status: 0
Course: Business and Communication
Nationality: 3




Theme © iAndrew 2016 - Forum software by © MyBB