Jump to content

arrays in mysql


claro

Recommended Posts

is  it possible to save it this way? I found no errors but there are also no effect in my db. help me guys! thank you. 

 

"while ($row = mysql_fetch_array($query))

  {

 

 

  echo "<tr>";

  echo  '<td><input type="hidden" name="se_Id['.$i.']">'.$row['se_Id'].'</td>';

  echo '<td><input type="hidden" name="user_Id['.$i.']">'.$row['user_Id'].'</td>';

  echo '<td><input type="hidden" name="course_Id['.$i.']">'.$row['course_Id'].'</td>';

  echo '<td><input type="hidden" name="ap['.$i.']">'.$row['ap_Id'].'</td>';

  echo "<td>". $row['user_Fname']."</td>";

  echo "<td>". $row['user_Lname']."</td>";

  echo "<td></td>";

  echo "<td></td>";

  echo "<td>".$row['se_Yearlevel']."</td>";

  echo "<td></td>";

  echo "<td></td>";

  echo "<td></td>";

  echo "<td>    <input type='checkbox' id='checkbox".$i."' value ='checked' onclick='checkbox_disabled(\"checkbox".$i."\",\"textbox".$i."\",\"checkbox".$i."2\");'></td>";

  echo "<td><input type='checkbox' id='checkbox".$i."2'>";

  echo "  <input type='text' id='textbox".$i."'></td>";

  echo "</tr>";

  $i++;

 

  }

  }

else

{

echo "No students enrolled";

}

  echo "</form>";

 

echo "</table>";

echo "<br></br>";

echo "  <input type='submit' name = 'submit' value='Submit'>";

 

?>

 

<?php

  if (isset($_POST['submit']))

  {

      foreach ($_POST['user_Id'] as $key => $user_Id)

      {

        $se_Id = $_POST['se_Id'][$key];

        $status = $_POST['status'][$key];

        $course = $_POST['course'][$key];

$officeid [$key];

        $ap = $_POST['ap'][$key];

        mysql_query("INSERT tbl_data (user_Id,se_Id,office_Id,course_id,ap_Id,Status)

VALUES ('$user_Id','$se_Id','$officeid','$course','$ap','$status')")

        or die(mysql_error());

// echo "<meta http-equiv=\"refresh\"content=\"0;URL=offcourse_view.php\">";

echo "congrats";

              }

 

}

?>"

 

Link to comment
https://forums.phpfreaks.com/topic/248093-arrays-in-mysql/
Share on other sites

OK, rip out all the $i's in the input name arrays, you don't need them - especialy if your just going to run a foreach anyway.  repost the entire page inside php tags ['php']...['/php'] (without the quotes) and please explain what exactly you are trying to do here.

Link to comment
https://forums.phpfreaks.com/topic/248093-arrays-in-mysql/#findComment-1273948
Share on other sites

<?php
$course1 = $_POST['course'];
$courses = mysql_query ("SELECT course_Title FROM tbl_course WHERE course_Id = '$course1'")
or die (mysql_error());
$result = mysql_fetch_array($courses);
$course = $result['course_Title'];

$program = $_POST['program'];

echo "<br></br>";
echo "<td><b>  Course:       <i>".$course."</i></b></td><br/>";
echo "<td><b>  Program:    <i>".$program." "."Class</b></i></td>";
echo "<br></br>";

echo "<form action = '#' method = 'POST'>";
echo "<table>";

$query = mysql_query("SELECT * FROM tbl_studenroll, tbl_user WHERE user_Level = 'Student' 
				AND course_Id = '$course1' 
				AND user_Program = '$program' 
				AND tbl_user.id = tbl_studenroll.user_Id
				ORDER BY se_Yearlevel DESC ")
		or die (mysql_error());

   if  (mysql_num_rows($query)>0)
{   

   echo "<tr>";
   echo "<td></td><td></td><td></td><td></td><th>Student's</th><th>Name</th><td></td><td></td><th>Year</th><td></td><td></td><td></td><th>Cleared</th><th>Not Cleared</th>";

   echo "<tr/>";
   while ($row = mysql_fetch_array($query))
   {
   echo "<tr>";
   echo  '<td><input type="hidden" name="se_Id" value='.$row['se_Id'].'></td>';
   echo '<td><input type="hidden" name="user_Id" value='.$row['user_Id'].'></td>';
   //echo '<td><input type="hidden" name="course_Id" value='.$row['course_Id'].'></td>';
   echo '<td><input type="hidden" name="ap" value='.$row['ap_Id'].'></td>';
   echo "<td>". $row['user_Fname']."</td>";
   echo "<td>". $row['user_Lname']."</td>";
   echo "<td></td>";
   echo "<td></td>";
   echo "<td>".$row['se_Yearlevel']."</td>";
   echo "<td></td>";
   echo "<td></td>";	
   echo "<td></td>";
   echo "<td>    <input type='checkbox' id='checkbox' value ='checked' onclick='checkbox_disabled(\"checkbox\",\"textbox\",\"checkbox2\");'></td>";
   echo "<td><input type='checkbox' id='checkbox".$i."2'>";
   echo "  <input type='text' id='textbox'></td>";
   echo "</tr>";
   

   }
  }
else
{
echo "No students enrolled";
}
   echo "</form>";
   
echo "</table>";
echo "<br></br>";
echo "  <input type='submit' name = 'submit' value='Submit'>";

  if (isset($_POST['submit']))
   {
      foreach ($_POST['user_Id'] as $key => $user_Id)
      { 
         $se_Id = $_POST['se_Id'][$key]; 
         $status = $_POST['status'][$key];
         $course = $_POST['course'][$key];
	 $officeid [$key];
         $ap = $_POST['ap'][$key];

	 echo $se_Id;
	 echo $status;
	 echo $course;
	 echo $officeid;
	 echo $ap;



         mysql_query("INSERT tbl_data (user_Id,se_Id,office_Id,course_id,ap_Id,Status)
				VALUES ('$user_Id','$se_Id','$officeid','$course1','$ap','$status')")
         or die(mysql_error());
	// echo "<meta http-equiv=\"refresh\"content=\"0;URL=offcourse_view.php\">";
echo "congrats";
              }


		}		
	?>


 

I did it already. then?

 

Link to comment
https://forums.phpfreaks.com/topic/248093-arrays-in-mysql/#findComment-1273955
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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