ebolt007 Posted November 27, 2011 Share Posted November 27, 2011 I have a database where I have 2 departments, and I want it to not show if they are both taken, but I'm not sure how to do this? Currently I have $type_sql2 = mssql_query("SELECT * FROM Database2 Where SaleID ='$salesid'"); while($RS2 = mssql_fetch_assoc($type_sql2)) { $used_dist = $RS2['DistID']; $type_sql = mssql_query("SELECT * FROM Database Where Disable = 0 AND DeptID!= '$used_dist'"); while($RS = mssql_fetch_assoc($type_sql)) { $DeptID_ID = $RS['DeptID']; $DeptID_Name = $RS['DeptDescription']; echo "<option value=\"$DeptID_ID\">$DeptID_Name</option>\n"; } } And my DeptID is SE and CM, now in another database where these are used, I want this to not show them if they are both used and only show the one not being used any other time, but I can't just do it one at a time, because I may have more departments later on, but right now, with the above, if one is used, then it works, because only one shows up, but if both are used, it shows both still because it then sees SE and puts in CM, then loops thru again and sees CM and puts in SE then the second time. I hope this makes sence. But how do I not show either if both are used, and if one is used then only show the other? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/251903-shows-both-departments-in-while-loop/ Share on other sites More sharing options...
ebolt007 Posted November 28, 2011 Author Share Posted November 28, 2011 Does anyone know how to show the "CM"($DeptID_Name) if the SE is being used already, in a dropdown lets say, or not show either if both are being used? My other question is, if I try to have 2 departments in a loop, and I set a save, let's say I have Departments CM and SE, and in the top table are all CM's then in the bottom are all SE's, now I have to Save both of these, but also add up the percentages I pull in each department. Which I can do fine, but then I have 2 save buttons. Below is the code. Basically, if the percentage values in either the CM or the SE departments doesn't =100% I don't want the save showing up at all, but if both equal 100% then I want the save showing up. I can't do this as if it ='s $200% because then someone could put in 125% in one department and 75% in another. So how do I do this? It's basically the same question as above, I need to know how to do a loop, and count either one or both. $type_sql4 = mssql_query("SELECT * FROM mydatabase1 WHERE SaleID='$salesid';"); while($percentage_row4 = mssql_fetch_assoc($type_sql4)) { $dist_name2 = $percentage_row4['DistID']; $test = 0; $type_sql2 = mssql_query("SELECT * FROM mydatabase2 WHERE SaleID='$salesid' AND DistID ='$dist_name2';"); while($percentage_row3 = mssql_fetch_assoc($type_sql2)) { $percent_edit = $percentage_row3['SalesPercent']; $percentage_format_number = ($percent_edit) * 100; $dist_percent = $percentage_format_number; $test += $percentage_format_number; } if ($test == 100){ echo "<input type=\"submit\" name=\"Save_Changes\" value=\"Save\">"; }else if ($test != 100){ echo "<div style=\"color:red;\">Percentage must be at 100% to save you are currently at $test%</div>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/251903-shows-both-departments-in-while-loop/#findComment-1291917 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.