tgreco88 Posted June 28, 2010 Share Posted June 28, 2010 So, I had this task assigned to me, but I'm really rusty at php. If anyone could help me, I would sincerely appreciate it. What I need to do: 1- Figure out what a drop down menu looks like in php, because in my code, I can't even tell where the drop down menu is located. This code that I've inherited is gigantic, and it's really hard for me to isolate bits of it. 2- Once I figure out where the drop down menu is in page 1, I need to isolate the variable that the user has selected. And then send that variable to page2 via a button. ( I was assuming that I could use a form button to send the information, but I really don't know the proper syntax for sending variables. ) 3- Then, I need to use the variable from page1 as a drop down item on page 2. Thank you in advance for any help. Sorry, here is the drop down menu code for page1 <form name="jobForm" action="" method="post"> <div class="labelCol">Job:</div> <select name="jobID" class="jobSelect" onChange="changePage(this.form.jobID)"> <? $query = "select id, name, 'job' as type from jobs where "; $totalJobs = count($chargeNums); $i = 0; foreach ($chargeNums as $num) { $query.= " id='$num' "; ++$i; if ($i < $totalJobs) $query.= " or "; } $totalGroups = count($groups); if ($totalGroups > 0) { $query .=" union select id, name, 'group' as type from objGroups where "; $i = 0; foreach ($groups as $num) { $query.= " id='$num' "; ++$i; if ($i < $totalGroups) $query.= " or "; } } $query.=" order by type desc, name asc"; if ($totalGroups + $totalJobs > 0) { $result = mysql_query($query); $num_results = mysql_num_rows($result); } else $num_results = 0; for ($i =1; $i <= $num_results; ++$i) { $row = mysql_fetch_array($result); $appendStyle = ""; if ($curJobID == $row['id']) $appendStyle.=" selected "; if ($row['type'] == "group") { $appendStyle.=" class=\"groupColor\" "; echo "<option $appendStyle value=\"".$row['id']."\">".$row['name']; echo "</option>\n"; } else { echo "<option $appendStyle value=\"".$row['id']."\">".$row['id']; echo " — ".$row['name'].""; echo "</option>\n"; } } echo "</select><br>\n"; echo "</form><p>\n"; Link to comment https://forums.phpfreaks.com/topic/206098-this-is-a-noob-question-but-i-need-assistance/ Share on other sites More sharing options...
TOA Posted June 28, 2010 Share Posted June 28, 2010 Use cookies or sessions, and post what code you have or we can't help Link to comment https://forums.phpfreaks.com/topic/206098-this-is-a-noob-question-but-i-need-assistance/#findComment-1078368 Share on other sites More sharing options...
tgreco88 Posted June 28, 2010 Author Share Posted June 28, 2010 So could anyone please explain to me how exactly I would use cookies or sessions for this? Or would a form work? I've updated my original post to include the code. Link to comment https://forums.phpfreaks.com/topic/206098-this-is-a-noob-question-but-i-need-assistance/#findComment-1078373 Share on other sites More sharing options...
tgreco88 Posted June 28, 2010 Author Share Posted June 28, 2010 It shouldn't be this hard to figure out. But it is... I can't decide on what syntax is correct. I just need to look into that loop, find the currently selected variables *Looks like there is two of them* .$row['id']."\">".$row['name']; (I THINK, mind you, I'm a complete noob and could be wrong) Then I need to include those variables into a button which *When clicked* sends the variable information to another page. I have tried searching google, tutorials, etc. It's not helping too much. Does anyone know the proper syntax for something like this? Thank you all in advance. And sorry for bumping my own post twice, I couldn't figure out how to edit the second post. Link to comment https://forums.phpfreaks.com/topic/206098-this-is-a-noob-question-but-i-need-assistance/#findComment-1078389 Share on other sites More sharing options...
TOA Posted June 28, 2010 Share Posted June 28, 2010 Where are you getting $chargeNums and $groups? (If there's more relevant code please post it) And give it time, it's not going to be solved in an hour Link to comment https://forums.phpfreaks.com/topic/206098-this-is-a-noob-question-but-i-need-assistance/#findComment-1078391 Share on other sites More sharing options...
tgreco88 Posted June 28, 2010 Author Share Posted June 28, 2010 Here is the entire code for that page. <? session_name("paths"); session_start(); include ("mylib.php"); if (!isset($_SESSION['user'])) { errorPage("Error", "", 0, "You are not logged in.", "index.php"); } $userLevel = $_SESSION['userLevel']; $userID = $_SESSION["user"]; $fullName = $_SESSION["firstName"]." ".$_SESSION["lastName"]; if (isset($_GET['month']) && isset($_GET['year'])) { $curMonth = validateMonth($_GET['month']); $curYear = validateYear($_GET['year']); } else { $curMonth = date("m"); $curYear = date("Y"); } $prevMonth = $curMonth - 1; $prevYear = $curYear; $nextMonth = $curMonth + 1; $nextYear = $curYear; if ($prevMonth <= 0) { $prevMonth = 12; $prevYear--; } if ($nextMonth > 12) { $nextMonth = 1; $nextYear++; } $dateName = date("F", mktime(0,0,0,$curMonth, 1, $curYear)); $prevMonthName = date("F", mktime(0,0,0,$prevMonth, 1, $prevYear)); //$db = mysql_pconnect("localhost", "paths_user", "paths_pass") or die("Database connection failed."); //mysql_select_db("paths") or die (mysql_error()); $chargeNums = getAllowed($userID, 48, "job"); $groups = getAllowed($userID, 4, "group"); $curJobID = ""; if (isset($_GET['jobID']) && validateGroupID($_GET['jobID']) != -1) $curJobID = validateGroupID($_GET['jobID']); else if (isset($_GET['jobID']) && validateJobID($_GET['jobID']) != -1) $curJobID = validateJobID($_GET['jobID']); else if (count($chargeNums) > 0) { $curJobID = $chargeNums[0]; } else { errorPage("Error", $fullName, $userLevel, "You do not have permission to enumerate users for any charge numbers.", ""); } $jobType = ""; if (in_array($curJobID, $chargeNums)) { $jobType = "num"; $query = "select name from jobs where id='$curJobID'"; } else if (in_array($curJobID, $groups)) { $jobType = "group"; $query = "select name from objGroups where id='$curJobID'"; } else { errorPage("Error", $fullName, $userLevel, "You do not have permission to enumerate users for this charge number or group, or it is invalid.", "showjobs.php"); } $result = mysql_query($query); $num_results = mysql_num_rows($result); if ($num_results > 0) { $row = mysql_fetch_array($result); $jobName = $row['name']; } else { errorPage("Error", $fullName, $userLevel, "Invalid charge number or group.", "showjobs.php"); } printPreHeader("Hours by job", $fullName, $userLevel); ?> <script language="JavaScript"> function changePage(newLoc) { nextPage = "showjobs.php?jobID=" + newLoc.options[newLoc.selectedIndex].value + "&month=<?=$curMonth;?>&year=<?=$curYear;?>"; if (nextPage != "") { document.location.href = nextPage; } } </script> <? printPostHeader("Home", $fullName, $userLevel); echo "<div class=\"title\"> $jobName's planned hours for $dateName, $curYear:</div>\n<p>\n"; ?> <div style="width: 200px; float: left;" align="left"><a href="showjobs.php?jobID=<?=$curJobID;?>&month=<?=$prevMonth."&year=".$prevYear;?>"><< Previous Month</a></div> <div style="width: 200px; float: left;" align="center"><a href="showjobs.php?jobID=<?=$curJobID;?>&month=<?=date("m")."&year=".$curYear;?>">Current Month</a></div> <div style="width: 200px; float: left;" align="right"><a href="showjobs.php?jobID=<?=$curJobID;?>&month=<?=$nextMonth."&year=".$nextYear;?>">Next Month >></a></div> <div style="clear: both;"></div> <p> <form name="jobForm" action="" method="post"> <div class="labelCol">Job:</div> <select name="jobID" class="jobSelect" onChange="changePage(this.form.jobID)"> <? $query = "select id, name, 'job' as type from jobs where "; $totalJobs = count($chargeNums); $i = 0; foreach ($chargeNums as $num) { $query.= " id='$num' "; ++$i; if ($i < $totalJobs) $query.= " or "; } $totalGroups = count($groups); if ($totalGroups > 0) { $query .=" union select id, name, 'group' as type from objGroups where "; $i = 0; foreach ($groups as $num) { $query.= " id='$num' "; ++$i; if ($i < $totalGroups) $query.= " or "; } } $query.=" order by type desc, name asc"; if ($totalGroups + $totalJobs > 0) { $result = mysql_query($query); $num_results = mysql_num_rows($result); } else $num_results = 0; for ($i =1; $i <= $num_results; ++$i) { $row = mysql_fetch_array($result); $appendStyle = ""; if ($curJobID == $row['id']) $appendStyle.=" selected "; if ($row['type'] == "group") { $appendStyle.=" class=\"groupColor\" "; echo "<option $appendStyle value=\"".$row['id']."\">".$row['name']; echo "</option>\n"; } else { echo "<option $appendStyle value=\"".$row['id']."\">".$row['id']; echo " — ".$row['name'].""; echo "</option>\n"; } } echo "</select><br>\n"; echo "</form><p>\n"; if ($jobType == "num") { echo "<div class=\"labelCol\">Profile:</div><a href=\"profile.php?id=$curJobID\">$jobName ($curJobID)</a><br>\n"; //$query = "select jobAssign.job, jobAssign.hours as hours, jobActual.hours as actualHours, jobAssign.user, firstName, lastName from jobAssign left join jobActual on (jobAssign.job=jobActual.job and jobAssign.user=jobActual.user and jobAssign.monthNum=jobActual.monthNum and jobAssign.yearNum=jobActual.yearNum) left join userData on userData.id=jobAssign.user where jobAssign.job='$curJobID' and jobAssign.monthNum=$curMonth and jobAssign.yearNum=$curYear order by lastName, firstName asc"; $query = "select jobAssign.job, jobAssign.hours as hours, jobActual.hours as actualHours, jobAssign.user, firstName, lastName, 'planned' as type from jobAssign left join jobActual on (jobAssign.job=jobActual.job and jobAssign.user=jobActual.user and jobAssign.monthNum=jobActual.monthNum and jobAssign.yearNum=jobActual.yearNum) left join userData on userData.id=jobAssign.user where jobAssign.job='$curJobID' and jobAssign.monthNum=$curMonth and jobAssign.yearNum=$curYear ". "union select jobActual.job as job, jobAssign.hours as hours, jobActual.hours as actualHours, jobActual.user, firstName, lastName, 'unplanned' as type from jobAssign right outer join jobActual on (jobAssign.user=jobActual.user and jobAssign.job=jobActual.job and jobAssign.monthNum=jobActual.monthNum and jobAssign.yearNum=jobActual.yearNum) left join userData on userData.id=jobActual.user where userData.id is not NULL and jobAssign.job is NULL and jobActual.job='$curJobID' and jobActual.monthNum=$curMonth and jobActual.yearNum=$curYear ". "order by lastName, firstName asc"; //echo $query; } else { echo "<div class=\"labelCol\">Profile:</div><a href=\"profile.php?id=$curJobID\">$jobName</a><br>\n"; //$query = "select SUM(jobAssign.hours) as hours, SUM(jobActual.hours) as actualHours, jobAssign.user, firstName, lastName from jobAssign left join objMem on objMem.objectID=jobAssign.job left join jobActual on (jobAssign.job=jobActual.job and jobAssign.user=jobActual.user and jobAssign.monthNum=jobActual.monthNum and jobAssign.yearNum=jobActual.yearNum) left join userData on userData.id=jobAssign.user where objMem.groupID='$curJobID' and jobAssign.monthNum=$curMonth and jobAssign.yearNum=$curYear group by jobAssign.user, firstName, lastName order by lastName, firstName asc"; $query = "select SUM(hours) as hours, SUM(actualHours) as actualHours, user, firstName, lastName, 'planned' as type from (". "select jobAssign.job, jobAssign.hours as hours, jobActual.hours as actualHours, jobAssign.user, firstName, lastName, 'planned' as type from jobAssign left join jobActual on (jobAssign.job=jobActual.job and jobAssign.user=jobActual.user and jobAssign.monthNum=jobActual.monthNum and jobAssign.yearNum=jobActual.yearNum) left join userData on userData.id=jobAssign.user where jobAssign.monthNum=$curMonth and jobAssign.yearNum=$curYear ". "union select jobActual.job as job, jobAssign.hours as hours, jobActual.hours as actualHours, jobActual.user, firstName, lastName, 'unplanned' as type from jobAssign right outer join jobActual on (jobAssign.user=jobActual.user and jobAssign.job=jobActual.job and jobAssign.monthNum=jobActual.monthNum and jobAssign.yearNum=jobActual.yearNum) left join userData on userData.id=jobActual.user where userData.id is not NULL and jobAssign.job is NULL and jobActual.monthNum=$curMonth and jobActual.yearNum=$curYear) tj". " left join objMem on objMem.objectID=tj.job where objMem.groupID='$curJobID' group by user, firstName, lastName order by lastName, firstName asc"; //echo $query; } $result = mysql_query($query); $num_results = mysql_num_rows($result); ?> <form name="assignForm" action="dosethours.php" method="post"> <input type="hidden" name="jobID" value="<?=$curJobID;?>"> <input type="hidden" name="monthNum" value="<?=$curMonth;?>"> <input type="hidden" name="yearNum" value="<?=$curYear;?>"> <? if ($num_results > 0) echo "<div class=\"hoursRow\"><div class=\"nameCol\">Employee</div><div class=\"hoursCol\">Planned Hours</div><div class=\"hoursCol\">Actual Hours</div></div>\n"; $userCount = 1; $totalHours = 0; $totalActualHours = 0; while ($row = mysql_fetch_array($result)) { echo "<input type=\"hidden\" name=\"userID$userCount\" value=\"".$row['user']."\"><br>\n"; if ($userCount % 2 == 0) $rowClass = "hoursRowEven"; else $rowClass = "hoursRowOdd"; echo "<div class=\"$rowClass\"><div class=\"nameCol\"><a href=\"profile.php?id=".$row['user']."\">".$row['lastName'].", ".$row['firstName']."</a></div><div class=\"hoursCol\"><input class=\"hoursInput\" "; if ($jobType == "group") echo "disabled"; $hoursText = ($row['type'] == "planned") ? ($row['hours'] + 0) : ""; echo " type=\"text\" name=\"hours$userCount\" value=\"$hoursText\"> </div><div class=\"hoursCol\">".($row['actualHours'] + 0)."</div></div>\n"; echo "<input type=\"hidden\" name=\"prevHours$userCount\" value=\"".($row['hours'] + 0)."\">\n"; $totalHours += $row['hours']; $totalActualHours += $row['actualHours']; ++ $userCount; } if ($userCount > 1) { echo "<div class=\"totalHours\"><div class=\"nameCol\"> Total </div><div class=\"hoursCol\">$totalHours</div><div class=\"hoursCol\">$totalActualHours</div></div>\n"; if ($jobType == "num") { echo "<div style=\"width: 600px;clear: both;\"><div style=\"float: right; padding-left: 10px;\"><input type=\"submit\" value=\"Set Hours\" name=\"setBtn\"/> </div><div style=\"float: right; padding-left: 10px;\"><input type=\"submit\" value=\"Use $prevMonthName Hours\" name=\"setLastBtn\"/></div>\n"; echo "<div style=\"float: right\"><input type=\"submit\" value=\"Refresh Hours\" name=\"refreshBtn\"/></div></div>\n"; echo "<div style=\"clear: both;\"> </div>\n"; } else { echo "<div style=\"width: 600px;clear: both;\"><div style=\"float: right\"><input type=\"submit\" value=\"Refresh Hours\" name=\"refreshBtn\"/></div></div>\n"; echo "<div style=\"clear: both;\"> </div>\n"; } } else { echo "<div class=\"emptyList\" align=\"center\">There are no users with hours set</div>\n"; if ($jobType == "num") { echo "<div style=\"width: 600px;\" align=\"right\"><div style=\"float: right; padding-left: 10px;\"><input type=\"submit\" value=\"Use $prevMonthName Hours\" name=\"setLastBtn\"></div><div style=\"float: right\"><input type=\"submit\" value=\"Refresh Hours\" name=\"refreshBtn\"/></div></div>\n"; echo "<div style=\"clear: both;\"> </div>\n"; } else { echo "<div style=\"width: 600px;clear: both;\"><div style=\"float: right\"><input type=\"submit\" value=\"Refresh Hours\" name=\"refreshBtn\"/></div></div>\n"; echo "<div style=\"clear: both;\"> </div>\n"; } } ?> </form> <? if ($jobType != "group") { ?> <div style="height: 20px; margin-top:10px; margin-bottom: 10px;"><hr align="left" class="lineBreak"/></div> <form name="addjobForm" action="doaddjob.php" method="post"> <input type="hidden" name="jobID" value="<?=$curJobID;?>"> <input type="hidden" name="monthNum" value="<?=$curMonth;?>"> <input type="hidden" name="yearNum" value="<?=$curYear;?>"> <input type="hidden" name="type" value="job"> <div class="labelCol">Employee:</div> <select name="id" class="jobSelect"> <? $userIDs = getAllowed($userID, 128, "user"); $users = getObjNames($userIDs); foreach ($users as $objID=>$obj) { echo "<option value=\"$objID\">$obj</option>\n"; } ?> </select> <input class="addBtn" type="submit" value="Add" name="addBtn"></p> </form> <? } printFooter(); ?> Yeah, it's a lot of code. The code from the first post is just what I thought the drop down menu would be. So here's the run down- this small company that I'm interning at was working on this alternative project to follow charge numbers and hours worked. But the guy who was programming this left the co. So they decided to toss me on the problem. No due date, and I have no expectations of this being solved in one hour.. I just don't have much else to do except try to figure this out. So my goal here is to add a button at the bottom of that page which, when clicked, will take whatever option is selected in the dropdown menu, and toss it to another page (createreport.php). Link to comment https://forums.phpfreaks.com/topic/206098-this-is-a-noob-question-but-i-need-assistance/#findComment-1078401 Share on other sites More sharing options...
TOA Posted June 28, 2010 Share Posted June 28, 2010 Just to clarify, I wasn't being condesending Sounds like an impossible task for an intern lol Gotta love gofer's (no offense) So, back to the topic... If you just have one menu named "menu1" for example. If you hit submit, that value is already available to you in the POST array as $_POST['menu1'] (can't remember if you'd need the single quotes here or not, would need to check that) . I can take a deeper look at this later, but still at work That variable could then be plugged into the search params And back to the OP, you will be able to tell what the menu looks like because it will be sent to output (either using echo or print) as HTML. You should be familiar with that...<select> and <option> tags Hope that helps, Ill dig in deeper to in a bit Link to comment https://forums.phpfreaks.com/topic/206098-this-is-a-noob-question-but-i-need-assistance/#findComment-1078453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.