1 Replies - 1217 Views - Last Post: 18 March 2013 - 06:55 AM Rate Topic: -----

#1 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

Display Data From Array in a table

Posted 18 March 2013 - 04:39 AM

I'm developing a small shopping cart with the flowing code

if($action == 'add')
	{
		if(!isset($_SESSION["Cart"])||count($_SESSION["Cart"])<1)
		{
			/* checn wether the cart is empty if it is create a new cart */
			
			
			$_SESSION["Cart"] = array(1=>array("App_ID" => $id,"Name"=>$APP));
		}
		
		else
		{
			/* If the cart is not empty add More items to cart */
			
			array_push($_SESSION["Cart"],array("App_ID" => $id,"Name"=>$APP));
			
		
			
		}
	}


i can get the all data to the Multidimensional Array
but i want to display This as a table
Table Have two Headers 1 -> Application_ID 2 -> Application_Name (both values stored in array)

i want to Display This array in a table
what i have so far

<?php
						
							echo "<table>";
						
							echo "<tr>";
							
								echo "<th>";
									echo "APPID";
								echo "</th>";
								
								
								echo "<th>";
									echo "AppName";
								echo "</th>";
								
								
							
							echo "</tr>";
							
							
							$i = 0;
								
							foreach($_SESSION["Cart"] as $each_item)
							{
								$i++;
								
								while(list($key,$value) = each($each_item))
								{
									echo "<tr>";
									
										echo "<td>";
											echo "$value"; 
										echo "</td>";
									
										echo "<td>";
											echo "$value";
										echo "</td>";
										
									
										
									echo "</tr>";
									
									
									
									
								}
								
							}
						
						
							echo "</table>";
						?>


This Give me the correct details but its not in a order i mean

1st row 1 cell have Applicatipn_ID
1st rOW 2 cell HAVE Applicatipn_ID

2nd row 1 cell haveApplicatipn_Name
2nd rOW 2 cell HAVE Applicatipn_Name

that is not what i want

i want


1st row 1 cell have Applicatipn_ID
1st rOW 2 cell HAVE Applicatipn_Name

2nd row 1 cell have Applicatipn_ID
2nd rOW 2 cell HAVE Applicatipn_Name

how do i archive this

Is This A Good Question/Topic? 0
  • +

Replies To: Display Data From Array in a table

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2993
  • View blog
  • Posts: 10,347
  • Joined: 08-August 08

Re: Display Data From Array in a table

Posted 18 March 2013 - 06:55 AM

In line 8 you set $_SESSION["Cart"] to an array containing one element that is itself an array. In line 15 you add an array of elements to $_SESSION["Cart"]. Did you intend to do this? It's going to make outputting things a bit tricky.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1