Hi is this correct syntax......i want the values which are displayed from the table should be stored in an array .......

<?php

	include('database.php');


 $stype=$_POST['category'];


if($stype=="service_category")
   { 
	 
	  $result = mysql_query("SELECT * FROM  service_category ");

	while($row = mysql_fetch_array($result))
	{

	?>

	<input type="Checkbox" id="a[]"  value="servicec"><?echo $row['servicec'];
	echo "<br />";
	for($i=0;$i<6;$i++)
		{
		   $a[i]=$row['servicec'];
		}
	}

   }

no, this code is not correct.

while($row = mysql_fetch_array($result))
{
?>
$a[i]=$row['servicec'];
$i++;
}

See this:

function get_all_listings() { 
  $query = "SELECT * FROM `metlistings`";
		
  $result = mysql_query($query) or die(mysql_error());
		
  //Count the rows retrieved
  $count = mysql_num_rows($result);	
  for ($i = 0; $i <= $count; $i++) {						    
    while($row = mysql_fetch_array($result)) {
	$title = stripslashes($row['metName']);
	$link = $row['metId'];
	$arr = array("listings" => array("total" => $count, "data" => array($i => $link)));
	
    return $arr; //doest not work
					
    //print_r($arr); //works fine
			
	}
     }
 
}
 
$test = get_all_listings();
for($i = 1; $i <= $test["listings"]["total"]; $i++) { 
 
  echo $test["listings"]["data"][$i];
	
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.