Forum Moderators: coopster

Message Too Old, No Replies

hiding characters in name field

         

Mopreme

6:41 pm on Oct 9, 2008 (gmt 0)

10+ Year Member



Hello

I have a problem and i have tried to fix it but don't get the right results. im wondering if this is actually possible to do.

I have a list of data on a php page.

its list all fields what begin with the letter a. then the user can select any of the letters from the alphabet and it displays all the data which begins with that letter.

my problem is a lot of the data starts with 'a name' or 'the item' or 'an item'

what i been trying to do is keep the title so it can be displayed in a details page, but on the list remove the words, 'a' 'an' 'the'.

i got this to work and the fields hide the words 'a' 'an' 'the' but on the list they still show in the A list or T list.

here is an example

original title is 'AN EXAMPLE' and is listed in the a list

with an hidden show 'EXAMPLE' but still in the a list.

i want it to be in the e list but still retain its real title

please could anyone point me in the right direction, im using php5 and mysql5

eelixduppy

7:24 pm on Oct 9, 2008 (gmt 0)



When you echo the results to the screen you are going to have to do a string replace on those prefixes. That way you still retain the data where you have it stored, just for display purposes it is "cleaned".

and Welcome to WebmasterWorld :)

andrewsmd

7:25 pm on Oct 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would reccomend storing all of your output into an array where the Key is "EXAMPLE" and the value is "An Example" then you could put them in the list by their key and display the title. Can you paste some code on how you are storing and displaying the names with your PHP and MySQL. I really can't help otherwise.

Mopreme

8:41 pm on Oct 9, 2008 (gmt 0)

10+ Year Member



Here is the main part of the code, i removed the search and page code.

this is the query and the tables


print("<p>$browsemenu<br>$pagemenu</p>");

$offset = ($page * $perpage) - $perpage;
$res = mysql_query("SELECT npcs.id as npcid, npcs.level, npcs.name, npcs.diff, npcs.npctype, npcs.planet, npcs.zone, npcs.location, planet.id, planet.name as planetname, zone.id, zone.name as zonename, diff.id, diff.name as diffname FROM (npcs, planet, diff) LEFT JOIN zone ON (npcs.zone=zone.id) WHERE $query and npcs.diff=diff.id and npcs.planet=planet.id ORDER BY npcs.name LIMIT $offset,$perpage") or sqlerr();
$num = mysql_num_rows($res);

print("<table border=1 cellspacing=0 cellpadding=5>\n");
print("<tr><td class=colhead align=left>Name</td><td class=colhead>Level</td><td class=colhead>Difficulty</td><td class=colhead>Planet</td><td class=colhead align=left>Zone</td><td class=colhead>Location</td><td class=colhead>NPC Type</td></tr>\n");
for ($i = 0; $i < $num; ++$i)
{
$arr = mysql_fetch_assoc($res);
$nname = stripslashes($arr['name']);
print("<tr><td align=left><a href=npcdetails.php?id=$arr[npcid]><b>$nname</b></a></td>" .
"<td>$arr[level]</td><td>$arr[diffname]</td><td>$arr[planetname]</td>".
"<td align=left>$arr[zonename]</td><td>$arr[location]</td><td>$arr[npctype]</td></tr>\n");
}
print("</table>\n");

print("<p>$pagemenu<br>$browsemenu</p>");

[edited by: Mopreme at 8:42 pm (utc) on Oct. 9, 2008]