claro Posted October 24, 2011 Share Posted October 24, 2011 I got this already, my problem is I can't get all values of my $prog array because of '=>' operator. Is there any way to get rid of this? foreach ($_POST['course'] as $val =>$course) { $prog = $_POST['program'][$val] ; echo $course; echo $prog; } Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 24, 2011 Share Posted October 24, 2011 What?! You must have no idea what you are doing because what you've stated makes absolutely no sense. The => operator does not prevent you in any way from accessing all the values of the array. If I had to guess, I would say that the arrays $_POST['course'] and $_POST['program'] do not have the same keys. So, why are you trying to use the key of one array to access the values of a different array? Since I do not understand the relationship of $_POST['course'] and $_POST['program'] in your application I cannot provide any advice on what you could do to solve your problem. Post what the typical values of the two arrays will hold and explain what you want to achieve Quote Link to comment Share on other sites More sharing options...
claro Posted October 24, 2011 Author Share Posted October 24, 2011 I'm sorry for that. Yes, I'm new in php. I just want to get the values of those two arrays, I tried to put it in a single foreach statement, I got the first value so I thought I'm near. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 24, 2011 Share Posted October 24, 2011 You will need to do a foreach on each array separately. However, if the two arrays have values that should be "associated" with each other and the arrays can have different number of elements you need to explain how they should be associated so we can help you. Again, providing an example of the contents of those arrays and an example of how you want them to be output would help. Quote Link to comment Share on other sites More sharing options...
claro Posted October 25, 2011 Author Share Posted October 25, 2011 thank you for your time. I did a research about array. I found a code that can get the value of my arrays and it went well. My problem is how to put it in my queries. Below is are my codes. $n=0; foreach ($_POST['course'] as $course) { $bigar[$n][1] = $course; $n++; } $n=0; foreach ($_POST['program'] as $program) { $bigar[$n][2] = $program; $n++; } foreach ($bigar as $part) { $course = $part[1]; $program = $part[2]; //echo $course; //echo $program; $stud = mysql_query ("SELECT * FROM vw_report_instructor WHERE user_Program = '$program' AND course_Id = '$course' ") or die (mysql_error()); if (mysql_num_rows($stud)) { while ($row = mysql_fetch_array ($stud)) { echo "<tr><td>".$row['user_Fname']." ".$row['user_Lname']."</td>"; echo "<td>".$row['course_Title']."</td>"; echo "<td>".$row['se_Yearlevel']."</td>"; echo "<td>".$row['user_Program']."</td></tr>"; } } else { echo "<table><br/><br/>"; echo "<p style = 'text-indent: 29em;'>no match found</p>"; echo "</table>"; } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.