Page 1 of 1

copy parts of query array

Posted: Thu Jul 15, 2004 9:05 am
by juline
dear friends,

i am working on my master thesis and programming for this purpose a timetable planningsystem for my university. i need an interface with checkboxes to copy two variables from table a to table b by checking a box. the data for the first interface is done. it lists the data from the base table a and contains the checkboxes.

Code: Select all

....
			//Datenausgabe
			for ($i=0; $i<count($resultArray); $i++)
			{
				echo "<tr>";
				echo "<td>";
				echo $lecture_nr=$resultArray[$i][0];
				echo "</td>";
				echo "<td>";
				echo $name_short=$resultArray[$i][1];
				echo "</td>";
				echo "<td>";
				echo $name=$resultArray[$i][2];
				echo "</td>";
				echo "<td>";
				echo $name_en=$resultArray[$i][3];
				echo "</td>";
				echo "<td>";
				echo "<input type='checkbox' name='nr[]' value='$lecture_nr'>";
				echo "</td>";
				echo "</tr>";

			}
		echo "<tr>";
        	echo "<td colspan=2 align='right' bgcolor='#EEEEEE'>";
        		echo "<input type='submit' value='Daten kopieren'>";
        		echo "<input type='reset' value='Eingaben l&ouml;schen'>";
        	echo "</td>";
	        echo "</tr>";
    	echo "</table>";
     	echo "</div>";
    	echo "</form>";
}

else
{
	$description = $_Post['name'];
	foreach ($_REQUEST['nr'] as $course_nr)
	{

 	$room_nr = '1';
 	$time_nr = '1';
	$day_nr = '1';

    if(!TimetablePlanning::copyLectureToCourse($link, $course_nr, $description, $room_nr, $time_nr, $day_nr))
    {
        handleError($link);
        exit();
    }
    	}
....
what i have done above is to declare $lecture_nr as $course_nr because the table in which those data need to be copied do have specific names.
now i want to copy also the lecture $name by declaring it as $description. how to do this ? is this problem solveable with checkboxes ?
sorry for my bad english in advance !
and also in advance thanks for help !

regards
juline


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Jul 15, 2004 11:03 am
by feyd
you can combine the 2 things as a single value string. i.e.

Code: Select all

$lecture_nr .= '|!@#|'.$name
then just [php_man]explode[/php_man] each value coming in through $_REQUEST['nr']

Posted: Thu Jul 15, 2004 3:15 pm
by juline
thanks feyd,
but where do i add this code ?

Posted: Thu Jul 15, 2004 3:19 pm
by feyd
to each checkbox value

Posted: Thu Jul 15, 2004 3:55 pm
by juline
ok. thanx.

and one more question:
how do i rename $lecture_nr to $course_nr and $name to $description like i did with this

Code: Select all

foreach ($_REQUEST&#1111;'nr'] as $course_nr)

Posted: Thu Jul 15, 2004 4:00 pm
by feyd

Code: Select all

foreach($_POST['nr'] as $val)
{
  list($course_nr,$description) = explode('|!@#|',$val,1);
  // continue with code....
}

Posted: Fri Jul 16, 2004 8:47 am
by juline
thank you feyd,

you helped me a lot ! it worked out.

Posted: Fri Jul 16, 2004 8:50 am
by juline
the result is this:

Code: Select all

...
				echo "<input type='checkbox' name='nr&#1111;]' value='$lecture_nr |!@#|$name'>";
				echo "</td>";
				echo "</tr>";

			&#125;
		echo "<tr>";
        	echo "<td colspan=2 align='right' bgcolor='#EEEEEE'>";
        		echo "<input type='submit' value='Daten kopieren'>";
        		echo "<input type='reset' value='Eingaben l&ouml;schen'>";
        	echo "</td>";
	        echo "</tr>";
    	echo "</table>";
     	echo "</div>";
    	echo "</form>";
&#125;

else
&#123;
	foreach ($_POST&#1111;'nr'] as $val)
	&#123;
	list($course_nr,$description)= explode('|!@#|',$val);
	$room_nr = '1';
	$time_nr = '1';
	$day_nr = '1';

    if(!TimetablePlanning::copyLectureToCourse($link, $course_nr, $description, $room_nr, $time_nr, $day_nr))
    &#123;
        handleError($link);
        exit();
    &#125;
    	&#125;
...