You are here: Problem with alphabet script - help needed « All PHP « IT news, forums, messages
Problem with alphabet script - help needed

Posted by skinnybloke on 08/18/05 12:08

Hi - I have the code below to display numbers and letters on a web
page. The script queries a database and selects the first character of
each company on there.

If the character exists on the database it creates a link for that
character, else it just displays the character.

This works fince except it is creating a link for number "0" yet there
are no company_name records beginning with "0". I currently only have
3 records on the database and all start with an alpha character yet
the script is showing the numeric 0 as a linkable field.

Does anybody know why this could be happening and how I could prevent
it?


<?php

// This section generates the numbers and letters for the company
search

$query = 'SELECT DISTINCT LEFT(company_name,1) FROM members';

$result = mysql_query($query);
while($row = mysql_fetch_array($result)) $alphanums[] = $row[0];

for ($numbers = 0; $numbers <= 9; $numbers++) {
if(in_array($numbers, $alphanums)) {
echo "<a href='directory_new.php?coletter=$numbers'>$numbers </a>";
} else {
echo "$numbers ";
}}

echo '<br />';
for ($alphabet1 = A; $alphabet1 <= M; $alphabet1++) {
if(in_array($alphabet1, $alphanums)) {
echo "<a href='directory_new.php?coletter=$alphabet1'>$alphabet1
</a>";
} else {
echo "$alphabet1 ";
}}

for ($alphabet2 = N; $alphabet2 != AA; $alphabet2++) {
if(in_array($alphabet2, $alphanums)) {
echo "<a href='directory_new.php?coletter=$alphabet2'>$alphabet2
</a>";
} else {
echo "$alphabet2 ";
}}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация