Need to limit display length of array

Hi,
I’m new at php and need to modify some code to limit the display length of an array.
Because of the amout of data in the database, this code is diplaying everything in the array.
I want to be able to adjust the limit hopefully by number and since have it display … at the end.

Here is the code.

[code]require_once(“common.inc.php”);

require_once(“config.inc.php”);

$sql = “SELECT area FROM $t_area WHERE countryid = $xcountryid”;

$area_res = mysql_query($sql);

if (mysql_num_rows($area_res))
{

?>
<?php
   echo "<b>$lang[AREAS_IN_SECTION]:</b> ";
	
	while($area_row = mysql_fetch_array($area_res))
	{
	
	$array[]= $area_row['areaname'];
	
	}

      $j=count($array);

		for($i=0;$i<$j;$i++)
		{

echo ‘’ . $array[$i] . ‘’;
//echo $array[$i];

			if($i< ($j-1)) 
			{
			
			echo '<font color="black">,</font> ';
			
			}
	    } 

}

?>

[/code]

would what I need be in $j=count($array); or $area_row

Thanks

Are you trying to limit the number of characters in any of the array’s elements, or are you trying to limit the total number of element for an array? If the former, you could use substr(), if the latter, you could use the LIMIT clause for SQL.

Ok, I was able to limit it.

$sql = "SELECT area FROM $t_area WHERE countryid = $xcountryid" LIMIT 10;
it appears I need to pagnate it using “…” instead of page numbers. How would I do that?

Thanks

I found a really nice tutorial via google. What did you find?

Sponsor our Newsletter | Privacy Policy | Terms of Service