Jump to content

Recommended Posts

These things are new to me.

 

I want to put these values




foreach ($_POST['course'] as $course)
{
		$c = mysql_query ("SELECT course_Id FROM tbl_course WHERE course_Title = '$course' ") or die (mysql_error());
		while ($row2 = mysql_fetch_array ($c))
		{
		echo $row2['course_Id']."<br/>";

		}

}

foreach ($_POST['program'] as $prog ) 	
{
	$p = mysql_query ("SELECT * FROM tbl_user WHERE user_Program = '$prog'") or die (mysql_error());
	while ($row = mysql_fetch_array ($p))
	{
	echo $row['user_Id']." ".$row['user_Fname']."<br/>";
	}
}	

 

 

to my queries below .

 

$stud = mysql_query ("SELECT  * FROM vw_report_instructor WHERE user_Id = '$user_Id'") or die (mysql_error());
while ($row = mysql_fetch_array ($stud))
{
	 $courseid = $row['course_Id'];
	 $seid = $row['se_Id'];
	 $userid = $row['user_Id'];

	 $name = mysql_query("SELECT user_Fname, user_Lname , user_Program FROM tbl_user WHERE id = '$userid' and user_Program = '$prog '") or die (mysql_error());
	 while ($row2 = mysql_fetch_array($name))
	 {
		$fullname = $row2['user_Fname']." ".$row2['user_Lname'];
		$program = $row2['user_Program'];


		$course = mysql_query ("SELECT course_Title FROM tbl_course WHERE course_Id = '$courseid'") or die (mysql_error());
		while ($row3 = mysql_fetch_array($course))
		{
				$course = $row3['course_Title'];
				$year = mysql_query ("SELECT se_Yearlevel FROM tbl_studenroll WHERE se_Id = '$seid'") or die (mysql_error());
				while ($row4 = mysql_fetch_array ($year))
				{
				$fullname = $row2['user_Fname']." ".$row2['user_Lname'];
				$program = $row2['user_Program'];
				$year = $row4['se_Yearlevel'];
				echo "<tr><td>".$fullname."</td>";
				echo "<td>".$course."</td>";
				echo "<td>".$year."</td>";
				echo "<td>".$program."</td></tr>";
				}
		}


	}

 

$user_Id can be found in my first query, while $prog in second .

Link to comment
https://forums.phpfreaks.com/topic/249650-im-dead-branching-foreach-and-queries/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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