Jump to content


Photo

Display initials navigation menu with links or not


  • Please log in to reply
7 replies to this topic

#1 djavet

djavet
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 01 September 2005 - 02:12 PM

Hello

I wich to make a address book with a initials navigation with link on. No problem until now, it's working perfectly (php + mysql wit Dreamweaver MX2004).

Now I wisch to show in my initals naviagtion menu only links where I've entries regarding my address book name field.

Per exemple:
A B C D E F G H I J K etc...

and i've only entrie on C and J, i wish on C and J a link.
Other not.

How it is possible to do that?
A lot of thx for your help and time.

Regards, Dom

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 01 September 2005 - 02:41 PM

im not sure how you would do this using dreamweaver interface but heres a way you should be able to do it using PHP coding

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]
$alphabet=(\'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\');
$query=mysql_query(\"select distinct(initial) FROM table\");
while ($r=mysql_fetch_array($query)) {
$initial=$r[\'intial\'];
$links=str_replace(\"$initial\",\"<a href=\\"$initial.php\\">$initial</a>\",$alphabet);
}
echo(\"$links\");
[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

that *should* work you will just have to change the table name, field name and so on :)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 djavet

djavet
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 01 September 2005 - 02:43 PM

Hello

Thx I will try this.
I wil give feedback.

Regards, DOm

#4 djavet

djavet
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 01 September 2005 - 02:46 PM

Just a little question:
on "select distinct(initial) FROM table"
is initial a DB field name or a funciton?

I use Mysql and not Coldfusion.

Regards, Dom

#5 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 01 September 2005 - 02:58 PM

intial is just the field, i was working along the lines that you already have an intial field
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#6 djavet

djavet
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 01 September 2005 - 03:06 PM

intial is just the field, i was working along the lines that you already have an intial field

View Post


I see! I'n only a field "Organisation" wich I must extract the first letter (don know how, but I will find!).

Thx, Dom

#7 djavet

djavet
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 01 September 2005 - 09:02 PM

Hello

I try you code in this way:
<?php require_once('../../Connections/connect.php'); ?>
<?php
mysql_select_db($database_connect, $connect);
$query_rsInitials = "SELECT DISTINCT UPPER(LEFT(organisation,1)) FROM contacts ORDER BY organisation ASC";
$rsInitials = mysql_query($query_rsInitials, $connect) or die(mysql_error());
$row_rsInitials = mysql_fetch_assoc($rsInitials);
$totalRows_rsInitials = mysql_num_rows($rsInitials);
?>
<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<?php
$alphabet=('A B C D E F G H I J K L M N O P Q R S T U V W X Y Z');
while ($r=mysql_fetch_array($rsInitials)) {
$initial=$r['organisation'];
$links=str_replace("$initial","<a href=\"$initial.php\">$initial</a>",$alphabet);
}
echo("$links");
?>
</body>
</html>
<?php
mysql_free_result($rsInitials);
?>

And I receive for every letter the error:

Notice: Undefined index: organisation in g:\elce\www.website.ch\cms\address\letters.php on line 18


Any idea where I'm wrong?

Regards, Dom

#8 djavet

djavet
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 September 2005 - 06:07 AM

I found!

I must change my query to:
SELECT DISTINCT UPPER(LEFT(organisation,1)) AS organisation FROM contacts

and then change all $links to $alphabet.

It's working now.
Thx a lot.

REgards, DOm




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users