Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Thu Nov 15, 2007 2:26 pm Reply with quote

I have a project I am working on where I have a many to many relationship between Courses and Directors. Courses can have more than one Director and Directors can teach many Courses.

I am trying to address this by having a Director field in the Courses table where I house an array of Director_ID's.

This code works for adding Courses and selecting more that one Director.

Code:


echo "<tr><td bgcolor='$bgcolor2'>Course Director(s):</td>\n";
echo "<td><select name=\"Director[]\" size=\"4\" multiple\">";
$directorlist = "SELECT Name_Last, Name_First, Director_ID FROM ".$prefix."_directors ORDER BY Name_Last;";
$result = $db->sql_query($directorlist);
while ( $row = $db->sql_fetchrow($result) ) {
   $selected = "";
   echo "<option value=\"" . $row['Director_ID'] . "\" $selected >" . $row['Name_First'] ." ". $row['Name_Last'] . "</option>";
}
echo "</select> (Control+Click) for multiple selections</td></tr>";


What I need now is a way to read this array when I EditCourse.php

I will have a list box that will list all Directors and any Director that already exist in the array will be selected in the list box.

So I need to explode the array and read the values and do a loop.

I selected * from Courses where Course_ID = '$CourseID' and read the value of Director

$Director = $info[Director];
$Director = explode(", ", $Director);

Now in my CourseEdit.php page I have this:

Code:


echo "<tr><td bgcolor='$bgcolor2'>Course Director(s):</td>\n";
echo "<td><select name=\"Director[]\" size=\"4\" multiple\">";
$directorlist = "SELECT Name_Last, Name_First, Director_ID FROM ".$prefix."_directors ORDER BY Name_Last;";
$result = $db->sql_query($directorlist);
while ( $row = $db->sql_fetchrow($result) ) {
   $selected = "";
   if ($row['Director'] == $Director) { $selected = "selected"; }
   echo "<option value=\"" . $row['Director_ID'] . "\" $selected >" . $row['Name_First'] ." ". $row['Name_Last'] . "</option>";
}
echo "</select> (Control+Click) for multiple selections</td></tr>";


But I am missing the loop where I read the values of what is in the array.

How do I implements this? I know I'm "in the ballpark" but need an assist.
 
View user's profile Send private message Visit poster's website ICQ Number
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Thu Nov 15, 2007 5:38 pm Reply with quote

Code:


$directorlist = "SELECT Name_Last, Name_First, Director_ID FROM ".$prefix."_directors WHERE Director_ID IN (" . $info['Director'] . ") ORDER BY Name_Last;";


I use the IN command to select different values of Director_ID

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©