copy parts of query array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

copy parts of query array

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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']
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

thanks feyd,
but where do i add this code ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

to each checkbox value
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

foreach($_POST['nr'] as $val)
{
  list($course_nr,$description) = explode('|!@#|',$val,1);
  // continue with code....
}
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

thank you feyd,

you helped me a lot ! it worked out.
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post 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;
...
Post Reply