/    Sign up×
Community /Pin to ProfileBookmark

A to Z dynamic listing

I have 500 names on a database and I created a static A-Z html listing that anchors dynamically to a variable link in my query

[code=php]
$anchorlink = strtolower(substr($lastname, 0, 1));

if ($tempanchor != $anchorlink) {
print(“<h3><a name=”$anchorlink”></a>”.strtoupper($anchorlink).”</h3>n”);
}
[/code]

I noticed that there is no last names that end with a ‘U’ so I have to make my A to Z list dynamically to check if a record with that list exists and make the link active or not-active depending on the availability of the record. Does anyone know on how to go about this? I know I have to check with a query to see if the record exists from a table and then i dont know.put it in a for loop? any suggestions are welcomed! thanks!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsJan 27.2005 — trySELECT COUNT(last_name LIKE '%a') FROM table
Copy linkTweet thisAlerts:
@vicpal25authorJan 27.2005 — nope that just counts how may records are there in the table, i need to check if any names that start with an A and check true and then check for B and then true and then C if not then false and so forth. I dont know if i can do this with a query.
Copy linkTweet thisAlerts:
@ShrineDesignsJan 27.2005 — this works, but you would need to send 26 queries to the serverSELECT COUNT(*) FROM <span><code>table</code></span> WHERE <span><code>last_name</code></span> LIKE '%a'i think if you query the entire table then use a reg exp it would be more efficient[code=php]<?php
$db = mysql_connect('localhost', 'root', '');
mysql_select_db('dbname', $db);

$result = mysql_query("SELECT last_name FROM table ORDER BY last_name ASC");
$names = array();
$count = array();

for($i = 0; $i < 26; $i++)
{
$count[chr(97 + $i)] = 0;
}
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$names[] = $row[0];

if(preg_match("/^[a-z]{1}/i", $row[0], $match))
{
$count[strtolower($match[0])] += 1;
}
}
print_r($count);
?>[/code]
Copy linkTweet thisAlerts:
@george1234Jan 28.2005 — If you have a frontend for your database, so that everything already has its own page etc. you could take alook at a tool like HTML Indexer: http://www.html-indexer.com/
×

Success!

Help @vicpal25 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...