Page 1 of 1

Store multiple selection from pagination info into single ar

Posted: Sat May 19, 2007 1:22 pm
by assgar
Hi

I was using a schroll bar to display multiple rows of dynamically created from database records.
The scrolling was not displaying the data properly so I have decided to use pagination.

The problem I am having is,
if I select one item on page #1 and another on page #5
only the last item selected on page #5 is stored in the array.

How can I store selections from multiple pages into one array?

Noite: I am using foreach loop to insert the selected record into a seperate table.


Code: Select all

<?php

session_start();

include("..db_connect_in.php");
?>

<html>
<body>
<form action ="../process.php" method="post">
<php?

		$mysqli = db_connect();
                db_select($mysqli, $db_id);


   /**----------------------------paging--------------------------------*/

	//how many rows to show per page
	$BottomRowsPerPage = 17;

	//by default we show first page
	$BottomPageNum = 1;
	//get the current page number
	if(isset($_GET['botpage']))
	  {
		$BottomPageNum = $_GET['botpage'];
	  }
	//counting the offset
	$BottomOffset = ($BottomPageNum - 1) * $BottomRowsPerPage;

 
	 /***************** determine which and how to select data to display ***************/
 	$query = "SELECT c.code_id, c.code, c.description
   		  FROM code c
		  WHERE c.fee_code = m.code
		  AND c.section_code = 'K'
		  ORDER BY c.fee_code";
	
	$BottomPagingQuery = "LIMIT $BottomOffset, $BottomRowsPerPage";
     	$result = mysqli_query($mysqli,$query.$BottomPagingQuery); //or die('Error, bot query failed');




            //search area display area layer and table
	    echo "<table width=\"99%\"  border=\"0\">
	            <tr align=\"center\" bgcolor=\"#FFFFFF\" height=\"\">
                     <td width=\"100%\" >
	              <div id=\"Layer2\" style=\"position:absolute; width:100%; height:550px; z-index:2; left: 12px; top: 305px;\">
                     <div id=\"pat-dash-scroll-box2\" style=\"overflow: off; float: left; width: 100%; height: 540px;  margin: 0px; \">\n";


			//table begins
             echo "<table width=\"99%\" height=\"332\" left =\"40\" align = \"\" border=\"0\" font face =\"arial\">\n";

	
         /**----------------------loop record to display----------------------**/

	$num_service = mysqli_num_rows($result);
	for($i=0; $i < $num_service; $i++)
		{
	            $row = mysqli_fetch_array($result);

 		    list($code_id, $fee1_code, $description) = $row;

	

		    //diaplay search results in rows
	  		echo"<tr height=\"10\">
				<td width=\"4%\" bgcolor=\"#fff8dc\" align=\"center\">
				    <input type=\"checkbox\" name=\"fee1_choice[$i]\" value=\"$code_id\"></td>
          			<td width=\"7%\" bgcolor=\"#fff8dc\" ><span class=\"style20\"><strong>$fee1_code</strong></span></td>
          			<td width=\"3%\" bgcolor=\"$bgcolor\" height=\"10\">
		 		    <input type=\"text\" name=\"fee1_unit[$i]\" size=\"1\" maxlength=\"2\" value =\"$fee1_unit\"/></td>
          			<td width=\"79%\" bgcolor=\"$bgcolor\" class=\"style20\"> $description </td>
            	       echo"</tr>\n";

		}//end of for loop




	   /**----------------Bottom pagination-------------------**/
		echo '<br>';
		//how many rows we have in database
		$result  = mysqli_query($mysqli,$query) or die('Error, 2 query failed');
		$BottomNumRows = mysqli_num_rows($result);

		//how many pages we have when using paging?
		$BottomMaxPage = ceil($BottomNumRows/$BottomRowsPerPage);

		$self = $_SERVER['PHP_SELF'];

		/** creating 'previous' and 'next' link plus 'first page' and 'last page' link
               print 'previous' link only if not on page one **/

		if ($BottomPageNum > 1)
			{
				$BottomPage = $BottomPageNum - 1;
				$BottomPrev = "<a href=\"$self?u_find=$find&u_field=$field&u_search=$searching&u_back=$back&u_special=$special&u_service=$services&u_sch_yr=$schedule_year&toppage=$TopPageNum&botpage=$BottomPage\">[Prev]</a> ";
				$BottomFirst = "<a href=\"$self?u_find=$find&u_field=$field&u_search=$searching&u_back=$back&u_special=$special&u_service=$services&u_sch_yr=$schedule_year&toppage=$TopPageNum&botpage=1\">[First Page]</a> ";
			}
			else
				{
					$BottomPrev  = '[Prev]';       // we're on page one, don't enable 'previous' link  ,
					$BottomFirst = '[First Page]'; // nor 'first page' link
				}

		//print 'next' link only if we're not
		//on the last page
		if ($BottomPageNum < $BottomMaxPage)
			{
				$BottomPage = $BottomPageNum + 1;
				$BottomNext = "<a href=\"$self?u_find=$find&u_field=$field&u_search=$searching&u_back=$back&u_special=$special&u_service=$services&u_sch_yr=$schedule_year&toppage=$TopPageNum&botpage=$BottomPage\">[Next]</a>";
				$BottomLast = "<a href=\"$self?u_find=$find&u_field=$field&u_search=$searching&u_back=$back&u_special=$special&u_service=$services&u_sch_yr=$schedule_year&botpage=$TopPageNum&botpage=$BottomMaxPage\">[Last Page]</a>";
			}
			else
				{
					$BottomNext = '[Next]';      // we're on the last page, don't enable 'next' link
					$BottomLast = '[Last Page]'; // nor 'last page' link
				}

			// print the page navigation link
			echo"<center> ". $BottomFirst . $BottomPrev . " <strong>$BottomPageNum</strong> of <strong>$BottomMaxPage</strong> pages " . $BottomNext . $BottomLast."</center>";


	 echo"</div>\n";
         echo "</div>\n";
	 echo "</table>\n";
        echo "</table>\n";



    $mysqli->close();//close connection to db

?>
</form>
</body>
</html>
:wink:

Posted: Sat May 19, 2007 8:39 pm
by Begby
Can you please clarify your question a bit? I have no idea what you are asking.

explain

Posted: Sun May 20, 2007 1:58 am
by assgar
Thanks for responding

I hope this explains things better.

The user is presentened with between 50 to 100 items (rows) dynamically retrived from the database.
Using paging (pagination) the 50 to 100 records are split into multiple pages with each page
displaying 18 rows per page to choose from using checkboxes.

Example:
The user might select the checkbox for an item on page # 1 and another item on page #5.
Currently I can only store multiple selection from page # 1 or page #5 in one array


I want to store multiple selections from page # 1 and page #5 in one array.

Posted: Sun May 20, 2007 2:17 am
by maliskoleather
so you want to be able to select boxes on multiple pages, then store the selections after they've looked through all the pages?

Posted: Sun May 20, 2007 3:47 am
by Kieran Huggins
Add the selections to an array in your $_SESSION variable... (you'll also need to start sessions at the top of your script)