I would appreciate some help on this one. i have achieved what i wanted but i don't know if this is the best way to go about it.
1st I queried the db.
mysql_select_db($database);
$sql_many_sections ="
SELECT sections.subject, sections.section_number, sections.classroom,
sections.level_id, sections.course, sections.campus, sections.times,
sections.shift
FROM sections
LEFT JOIN section_teacher
ON sections.section_number = section_teacher.section_number
LEFT JOIN profile
ON profile.teacher_number = section_teacher.teacher_number
WHERE profile_id ='{$colname_teacher}'
ORDER BY sections.section_number ASC";
// bring out the results as an array so I can loop through them later
$result = mysql_query($sql_many_sections);
confirm_query($result);
while ($teaching_sections = mysql_fetch_array($result)) {
$teaches[] = $teaching_sections;
}
Then I print_r the results which was.
Array
(
[0] => Array
(
[0] => English
[subject] => English
[1] => 32346
[section_number] => 32346
[2] => G635
[classroom] => G635
[3] => 2
[level_id] => 2
[4] => 236
[course] => 236
[5] => Male Science
[campus] => Male Science
[6] => 8 - 9:40 am, 10 - 11:40 am
[times] => 8 - 9:40 am, 10 - 11:40 am
[7] => AM
[shift] => AM
)
[1] => Array
(
[0] => English
[subject] => English
[1] => 49493
[section_number] => 49493
[2] => 1328
[classroom] => 1328
[3] => 2
[level_id] => 2
[4] => 236
[course] => 236
[5] => Male Humanities
[campus] => Male Humanities
[6] => 8 - 9:40 am, 10 - 11:40 am
[times] => 8 - 9:40 am, 10 - 11:40 am
[7] => AM
[shift] => AM
)
)
When I want to now return this data like this
• Section: 32346
• Subject: English
• Classroom: G635
• Level: 2
• Course: 236
• Campus: Male Science
• Shift: AM
• Shift times: 8 - 9:40 am, 10 - 11:40 am
The only way i could get it to work was by doing the below and that was an accident. What is the correct way to achieve these same results. Thanks
<?php
foreach($teaches as $value)
{ ?>
<ul>
<li>Section: <? echo $value[1];?></li>
<li>Subject: <? echo $value[0];?></li>
<li>Classroom: <? echo $value[2];?></li>
<li>Level: <? echo $value[3];?></li>
<li>Course: <? echo $value[4];?></li>
<li>Campus: <? echo $value[5];?></li>
<li>Shift: <? echo $value[7];?></li>
<li>Shift times: <? echo $value[6];?></li>
</ul>
<?
}
?>
mysql_*functions to write new code. They are no longer maintained and the community has begun deprecation process. See the red box? Instead you should learn about prepared statements and usemysql_fetch_assoc()instead ofmysql_fetch_array()and then use the associative keys when outputting, as in<? echo $value['subject']?>