Page 1 of 1

Problem with selection for "teacher" variable

Posted: Wed Nov 13, 2002 2:57 am
by Shinmeiryu
The script is intended to add a staff member to the location they are employed at.

The problem I am having is that:
<select name = "teacher">
<?
for ($y = 0; $y < sizeof($t); $y++)
{
?> <option value = "<?= $t[$y][0] ?>"> <?= $t[$y][2] . ", " . $t[$y][1] ?>
works for the first three locations that I submitted, but the most recent locations that I've added seems to refuse to show any of the teacher/staff member names on database in the selection bar. I've looked through the code the past couple of days and still miffed.

Code: Select all

&lt;?

   require("../require.inc");
   SQLinit();

   $result  = Authorize($Session, 0); // admin
   $result2 = Authorize($Session, 1); // ordinary guy

   OpenPage($Session);

   if ($result2 == 0)
   {
     echo "You must be logged in to submit anything";
     ClosePage();
     exit;
   }

   if ($Location == "")
   {
        if ($submit == "")
        {
           LocationList();
        }
   }
   elseif ($submit == "")
   {
        SubmitForm($Location);
   }

   if ($submit == "Submit")
   {
        DoQuery("insert into LocStaff (StaffId, LocationId) values ("$teacher", "$Id")", 0);
        $s = DoQuery("select count(*) from LocStaff where LocationId = $Id", 1);
        $ins = $s&#1111;0]&#1111;0];
        DoQuery("update LocStaff set Priority = $ins where 
                 StaffId = "$teacher" AND LocationId = "$Id"", 0);

        $r = DoQuery("Select *, Staff.LastName, Staff.FirstName from LocStaff
                      left join Staff on Staff.Id = LocStaff.StaffId where LocationId = $Id order by Priority", 1);
 
      ?&gt;
        &lt;p class = "normal"&gt;
          Success!
   Now feel free to 
&lt;a href = "/admin/index.php"&gt; go back &lt;/a&gt; to the main admin page.
&lt;/p&gt;
&lt;p class = "normal"&gt; Here are the teachers in this location: &lt;ol&gt;
      &lt;?
          for ($x = 0; $x &lt; sizeof($r); $x++)
          {
               echo "&lt;li&gt; " . $r&#1111;$x]&#1111;5] . ", " . $r&#1111;$x]&#1111;6] . " Priority #" . $r&#1111;$x]&#1111;3];
          }
    }

   ClosePage();
  

function SubmitForm($l)
{ 

$s = DoQuery("select * from Locations where Id = $l", 1);

$r = DoQuery("select StaffId, Staff.LastName, Staff.FirstName from LocStaff 
              left join Staff on Staff.Id = LocStaff.StaffId where LocationId = $l order by Priority", 1);

$w = DoQuery("select Staff.Id, LocStaff.LocationId from Staff
left join LocStaff on LocStaff.StaffId = Staff.Id where LocStaff.LocationId = $l", 1);

$esj = "";
for ($ssf = 0; $ssf &lt; sizeof($w); $ssf++) {

  if ($ssf != 0) $esj = $esj . ",";
  $esj = $esj . " ". $w&#1111;$ssf]&#1111;0];
  
$t = DoQuery("select Staff.Id, Staff.FirstName, Staff.LastName from Staff where Id not in ($esj)", 1);
}

?&gt;

   &lt;BR&gt;

&lt;span class = "title"&gt; Add Staff to Location #&lt;?= $s&#1111;0]&#1111;0] ?&gt; (&lt;?= $s&#1111;0]&#1111;1] ?&gt;) &lt;/span&gt;

&lt;p class = "normal"&gt; Current Staff &lt;/p&gt;

&lt;ul&gt;
&lt;?
   for ($x = 0; $x &lt; sizeof($r); $x++)
   {
       ?&gt;&lt;li&gt; &lt;?= $r&#1111;$x]&#1111;0] ?&gt;: &lt;?= $r&#1111;$x]&#1111;1] ?&gt;, &lt;?= $r&#1111;$x]&#1111;2] ?&gt;   &lt;?
   }

   if (sizeof($r) == 0)
   {
       ?&gt;&lt;li&gt; No Staff Listed at this time.  &lt;?
   }

?&gt;
&lt;/ul&gt;

&lt;form name = "SubmitPicture" action = "/admin/locationaddstaff.php" method = "POST"&gt;

&lt;table cellpadding = 0 cellspacing = 2 border = 0&gt;

&lt;tr&gt;&lt;td class = "normal"&gt;Teacher&lt;/td&gt;&lt;td&gt;

&lt;? 
  if (sizeof($t) == 50)
   {
       echo "All of your staff are employed here already";
   }
   else {
?&gt;

&lt;select name = "teacher"&gt;
&lt;?
   for ($y = 0; $y &lt; sizeof($t); $y++)
   {
      ?&gt;  &lt;option value = "&lt;?= $t&#1111;$y]&#1111;0] ?&gt;"&gt; &lt;?= $t&#1111;$y]&#1111;2] . ", " . $t&#1111;$y]&#1111;1] ?&gt; &lt;?
   }
?&gt;
&lt;/select&gt;

&lt;? } ?&gt;
 
&lt;input type = "hidden" name = "Id"   value = "&lt;?= $l ?&gt;"&gt;
&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;input type = "reset"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type = "submit" name = "submit" value = "Submit"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;&lt;a href = "/admin/index.php"&gt; Forget this &lt;/a&gt; and go back to the admin page.&lt;/p&gt;

&lt;/form&gt;

&lt;?

}

Function LocationList()
{
   $r = DoQuery("Select * from Locations", 1);

?&gt; &lt;p class = "title"&gt; Add Staff to Location &lt;/p&gt;

   &lt;ul&gt;
&lt;?

   for ($x = 0; $x &lt; sizeof($r); $x++)
   { ?&gt;
      &lt;li&gt; &lt;a href = "/admin/locationaddstaff.php?Location=&lt;?= $r&#1111;$x]&#1111;0] ?&gt;"&gt; &lt;?= $r&#1111;$x]&#1111;1] ?&gt; &lt;/a&gt;
   &lt;? }

?&gt;&lt;/ul&gt;&lt;?   

}
?&gt;

Posted: Wed Nov 13, 2002 3:07 am
by volka
uh, that's way too complex for me to solve it with a short glimps at the script ;)
But you may add code to DoQuery that will output the query and amount of returned recordsets as <!-- html-comment -->
Maybe your queries are not what they are supposed to be....

Posted: Wed Nov 13, 2002 5:13 am
by Shinmeiryu
Haha, I thought it would be a bit beefy. I suppose the queries aren't executing as I thought.

Everytime I've fiddled with DoQuery, I end up taking 5 steps back with query problems directed towards my include file. I would assume that the $t variable is the one that needs query adjustments, then I find myself with sometimes losing the recordset of all the submitted teachers in the select bar.

I'm sort of confused by your "html comment" though, wouldn't I just set a numerical limit?

Posted: Wed Nov 13, 2002 5:46 am
by volka
with <!-- html comment --> I meant to really output the query string to the output-stream ;)
like

Code: Select all

echo '&lt;!--', $theRealQuery, '--&gt;';
this will not effect the formatting of the document but you can view the comments in the browser's 'source view'.
Depending on your dataflow you may experience some 'cannot send header....'-errors.