SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, what I am trying to do is create a page where someone can sign students up for classes. First, they select the student. Then, a table comes up with periods. Each "period" has a corresponding list of available classes. The person would select an available class and that would assign that particular class to that student for that period.

    Well, right now, to do this, I am updating the null values in that student's period. This seems to be working fine.

    But, let's say the student already has a class picked for that period. Can I have it so that the first option selected is that class and it says "(already scheduled)" right before that option in the select box. And then, it would go on to list the available classes for that time, but it wouldn't list the one already selected. How can I go about doing that?

    aDog

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume you have a table of classes available I would load the classes into an array at the start of my script so that I could use the array again like

    $result = mysql_query("SELECT * FROM classtable");
    while ($row = mysql_fetch_array($result)) {
    $classlist[] = $row["classnamefield"];
    }


    Now when you are working with a student and you select the student and the period to assign a class for I assume you will query the student table to see if he/she has a class assigned that period if so you would just create the dropdown list from the array of classes and whilelooping through the array look for the class from the student table. and omit it something like:

    print "Current Selection for this period is ". $classfromstudenttable;
    print '<select name="classes">';
    while (list($key, $val) = each ($classlist)) {
    if ($val != $classfromstudenttable) {
    printf('<option value="%s">%s', $val, $val);
    }
    }
    print '</select>';


    or if you want to have the current class selected in the drop down list then

    print '<select name="classes">';
    while (list($key, $val) = each ($classlist)) {
    if ($val == $classfromstudenttable) {
    printf('<option value="%s" selected>%s', $val, $val);
    }
    else {
    printf('<option value="%s">%s', $val, $val);
    }
    }
    print '</select>';
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys,

    I probably did a longabout way of accomplishing this, but I did do it. Here's the code I used:

    Code:
    <?php
    		$periodNum=8; //number of periods
    		$countP=0;
    		$PN = array("1st","2nd","3rd","4th","5th","6th","7th","8th","9th");
    		echo("<input type=\"hidden\" value=\"$periodNum\" name=\"periodNum\"><input type=\"hidden\" name=\"SID\" value=\"$SID\">");
    		while($countP<$periodNum){
    			$period=$PN[$countP];
    ?>
    			<tr><td bgcolor="#73C0DD" width="18%" height="30"><font color="#CA3C3F" face="Verdana, Arial, Helvetica, sans-serif"><?php echo($period);?> Period</font></td><td bgcolor="#99E287" width="82%" height="30"> &nbsp; &nbsp; <select style="font-family:Arial;font-size:9pt" name="<?php echo($period);?>">
    <?php
    			$classsql2="SELECT Courses.ID, CN, UserName FROM Courses, Teachers, Students WHERE Students.ID=$SID AND Students.$period=Courses.ID AND Teachers.ID=TID";
    			$classsql=mysql_query($classsql2);
    			if($myrow = mysql_fetch_array($classsql)){
    				$classid=$myrow["ID"];
    				if($classid || $classid!=0){
    					$classCN=$myrow["CN"];
    					$classUserName=$myrow["UserName"];
    					echo("<option value=\"$classid\" selected>(Already Selected) $classCN ($classUserName)</option>\r");
    				}
    			}
    			$sql2="SELECT Courses.ID, CN, UserName FROM Courses, Teachers WHERE Period='$period' AND Teachers.ID=TID";
          			$sql=mysql_query($sql2);
    			while($myrow = mysql_fetch_array($sql)){
    				$id=$myrow["ID"];
    				if($classid!=$id){
    					$CN=$myrow["CN"];
    					$UserName=$myrow["UserName"];
    					echo("<option value=\"$id\">$CN ($UserName)</option>\r");
    				}
    			}
    ?>
    			</select></td></tr>
    <?php
    			$countP++;
    		}
    ?>
    Tell me if you see a better way to do it.

    aDog


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •