MySQL Forums
Forum List  »  Newbie

Re: Alphabetical Navigation
Posted by: Stuart Roe
Date: August 12, 2005 06:28AM

In try the following PHP. It should create a list of two characters in the $Result Array. It works by getting a list of names from the database and everytime $Counter returns to zero (because of the % 18) it pushes the current name's initial two characters into the results. The last if statement captures the last result if it has just been added to the results.

There are better places to be asking PHP questions, like the Community Forums at http://www.webxpertz.net/forums/

The PHP:

$Query = 'select name from table order by name';
$ResultSet=mysql_query($Query);

$Counter = 0;
$Result = array();
while($Row=mysql_fetch_assoc($ResultSet))
{
if( $Counter == 0 )
array_push($Result,substr($Row['name'],0,2));
$Counter = ($Counter + 1) % 18;
}
mysql_free_result($ResultSet);

if($Counter != 1)
array_push($Result,substr($Row['name'],0,2));

Options: ReplyQuote


Subject
Written By
Posted
August 11, 2005 02:49PM
Re: Alphabetical Navigation
August 12, 2005 06:28AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.