Need to limit display length of array

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.



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

$area_res = mysql_query($sql);

if (mysql_num_rows($area_res))

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



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

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




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


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?


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

Sponsor our Newsletter | Privacy Policy | Terms of Service