array problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jimath
Forum Newbie
Posts: 7
Joined: Fri Sep 23, 2005 3:56 am

array problem

Post by jimath »

I have 2 scripts and that i want to do is to give values in each textfield and each value to be displayed correspondingly in each field at the other page(INSERT_STUDENT_MARK).But the problem is that the script displays ALL the stored values of array MARK[] in each field. I do not know if i have to use array.
Have you got any idea? THANKS



HERE IS A PIECE OF THE CODE OF INSERT_MARKS_PER_LESSON

Code: Select all

echo "<FORM METHOD=\"POST\"  ACTION=\"insert_student_mark.php\" NAME=\"form\">"; 


$display_block .= " 
<table  celpadding=3 cellspacing=2 border=1 width=98%> 
<tr> 
<th>A/A:</th> 
<th>AM:</th> 
<th>NAME:</th> 
<th>SEMESTER:</th> 
<th>LESSON MARK:</th> 
</tr>"; 

while ($line=mysql_fetch_array($get_list_res)) 
{ 
$count++; 

$am=$line["am"]; 
$f_name=$line["f_name"]; 
$l_name=$line["l_name"]; 
$examino=$line["typical_examino"]; 
$lesson_id=$line["lesson_id"]; 



$display_block .= " <tr> 
<td align=center>$count<br></td> 
<td align=center>$am<br></td> 
<td align=center>$f_name  $l_name<br></td> 
<td align=center>$examino<br></td> 
<td>    <INPUT TYPE=text   NAME=\"mark[]\" </td> 


</tr>"; 


} 
$display_block .= "</table>"; 
print" $display_block"; 

echo "<input type=\"hidden\" name=\"submitted\" value=\"yes\" />\n"; 
echo "<input type=\"submit\" />\n"; 
echo "</form>"; 


?>
HERE IS A PIECE OF THE CODE OF INSERT_STUDENT_MARK

Code: Select all

$get_list = ("SELECT s.am, s.typical_examino, s.f_name, s.l_name, l.name_lesson,sm.student_mark, l.lesson_id 
FROM student AS s 
LEFT  JOIN lessons_per_exam AS l ON s.typical_examino >= l.examino 
LEFT JOIN students_marks as sm ON sm.lesson_id=l.lesson_id WHERE sm.student_mark <5 AND sm.student_am=s.am AND  l.lesson_id = $lesson_id 
AND sm.point='checked'"); 


$get_list_res = mysql_query($get_list) or die (mysql_error()); 

$display_block .= " 
<table  celpadding=3 cellspacing=2 border=1 width=98%> 
<tr> 
<th>A/A:</th> 
<th>AM:</th> 
<th>NAME:</th> 
<th>SEMESTER:</th> 
<th>LESSON MARK:</th> 
</tr>"; 

$count=0; 
while ($line=mysql_fetch_array($get_list_res)) 
{ 

$count++; 

$am=$line["am"]; 
$f_name=$line["f_name"]; 
$l_name=$line["l_name"]; 
$examino=$line["typical_examino"]; 
$lesson_id=$line["lesson_id"]; 
$funct=show_student_marks(); 

$display_block .= " <tr> 
<td align=center>$count<br></td> 
<td align=center>$am<br></td> 
<td align=center>$f_name  $l_name<br></td> 
<td align=center>$examino<br></td> 
<td align=center> $funct <br></td> 


</tr>"; 
} 


$display_block .= "</table>"; 
print" $display_block"; 



  function show_student_marks() { 
   
  $val = ''; 
  $mark = $_POST['mark']; 
  $submitted = $_POST['submitted']; 

  if ("yes" == $submitted) { 
       

    foreach ( $_POST['mark'] as  $value) { 
      if ($value < 1 || $value > 10 || $value==null) { 

        // concatonate your value to the end of $val instead of overwriting it 
        $val .= "<br>YOU GAVE WRONG MARK :$value "; 

      } else { 
                      
        $val .= "<br>$value<br>"; 
                              
      } 
    } 
  } 
   
  return $val;
Post Reply