Hello,

I am trying to store a single MYSQL result into a 2 dimensional array, for example I would like to end up with something like this:
array[0][0] = result[0] , array[0][1] = result[1] , array[0][2] = result[2] .....

Here is my code:

$tempCat = array();
		
		for ($i=0;$i<$numcat;$i++)
		{	
			$result = mysql_query("SELECT * FROM accs_subcat WHERE category='$cat2[$i]'");
			$j=0;
			while($row = mysql_fetch_array($result)) 
			{  
				$tempCat[$i][$j] = $row['subcat'];
				$j++;
			}
		}
		//to display results
		for ($i=0;$i<$numcat;$i++)
		{	
			$tempnum = count ($tempCat[$i]);
			for($j=0;$j<$tempnum;$j++)
			{
				echo "$tempCat[$i][$j]";
			}
		}

Any help with this would be very much appreciated, thank-you.

I managed to get it working....not entirely sure if the fixes I made were solutions to the original problem..but alas it works...

Here is my revised code:

$numcat = count($cat2);
		$temp1 = array();
		for ($i=1;$i<=$numcat;$i++)
		{	
			$t = $i - 1;
			$result = mysql_query("SELECT * FROM accs_subcat WHERE category='$cat2[$t]' ORDER BY subcat ASC");
			$j=1;
			while($row = mysql_fetch_array($result)) 
			{  
				$temp1[$i][$j] = $row['subcat'];
				$j++;
			}
		}
		$_SESSION['subcat'] = $temp1;
This question has already been answered. Start a new discussion instead.