Reply
A - Z Listing with script
Old 08-06-2005, 04:07 PM A - Z Listing with script
andypugh's Avatar
Novice Talker

Posts: 12
Hi Guys,

I have just begun using MySQL databases with PHP so i'm not very advanced, I was wondering if you could help me with something

I have managed to build a portal for a 'Characters' section on my harry potter site. www.hogsmeadenews.com

however it's starting to get quite long, I was wondering if someone would be able to show me how I would go about listing it a-z?

here is the code I have

PHP Code:

 <?
if ($newsid == "") {
$sql="SELECT * FROM characters ORDER BY newsname ASC";
$result=mysql_query($sql);
$ncount=0;
echo 
"<font size=1> </font>";
while (
$myrow=mysql_fetch_array($result)) {
if (
$ncount<300
{
$ncount=$ncount+1;
$newsbody str_replace("\'""'"$newsbody);
?>
                            <font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
                            <table width="100%" border="0" cellspacing="0" cellpadding="0"  bordercolor="#999999">
                              <tr> 
                                
                              <td width="99%"> 

                               
  <li><a href=index.php?page=characterread&newsid=<? echo $myrow["newsid"]; ?>

                              
                                 <b> 
                                 
                                <? echo $myrow["newsname"]; ?><Br>
                                </b> </a> </a>
                                
        </a>          
                                  </font>
                                  
                                
                                  
                                  </td>
                              </tr>
                            </table>
                            
                          <div align="left"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
                            </font>
                            <table width="100%" border="0" cellspacing="0" cellpadding="8">
                              <tr> 
                                <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
                                 
                                  </font></font></td>
                              </tr>
                            </table>
                            <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
                            </font></div>
                          </font> 
                          <div align="left">
                            <?
}
}
} else {
$sql="SELECT * FROM characters WHERE newsid=$newsid";
$result=mysql_query($sql);
$myrow=mysql_fetch_array($result);
printf("<div align=left><font face=Verdana size=1><a href=index.php?page=characters>Characters</a> / %s"$myrow["newsname"], $myrow["newsby"]);
printf("<Br><Br><font face=Verdana size=2>%s"$myrow["newsbody"]);

}
?>
that prints out the following page
http://www.castlefm.net/hogsmeade/in...age=characters

how i make that into a (A-B-C-D-E-F-G-H-I-J etc etc) listing?

any help you could give me would be so much appreciated guys!

Andy
andypugh is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 08-06-2005, 04:40 PM
chrishirst's Avatar
Super Moderator

Posts: 16,477
Location: Blackpool. UK
This should be in the PHP forum but,
PHP Code:
$first_char $_GET['firstchar']
if (
$first_char <> "") {
$sql="SELECT * FROM characters WHERE newsname LIKE '" $first_char "%' ORDER BY newsname 
ASC"

} else {
$sql="SELECT * FROM characters ORDER BY newsname ASC"

and the links would be

HTML Code:
<a href="page.php?firstchar=a" >A</a>
Repeat as required


Not tested, coding at the keyboard (always dangerous )

It could get a little more complicated if you want to use F to K for instance.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-06-2005, 05:05 PM
dvduval's Avatar
Ultra Talker

Latest Blog Post:
WebDirectory Template
Posts: 267
That's a cool idea for my link directory script. I think I will use this. Thanks!
dvduval is offline
Reply With Quote
View Public Profile Visit dvduval's homepage!
 
Old 08-06-2005, 05:31 PM
andypugh's Avatar
Novice Talker

Posts: 12
Hi, Were would i place that in my code?

Sorry if this was in the wrong place, I had no idea guys!
andypugh is offline
Reply With Quote
View Public Profile
 
Old 08-07-2005, 05:38 AM
chrishirst's Avatar
Super Moderator

Posts: 16,477
Location: Blackpool. UK
It replaces your existing $sql= line
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-07-2005, 01:29 PM
andypugh's Avatar
Novice Talker

Posts: 12
I can't get it to work

There are 2 $sql= lines and it works for neither

Andy
andypugh is offline
Reply With Quote
View Public Profile
 
Old 08-09-2005, 04:26 AM
chrishirst's Avatar
Super Moderator

Posts: 16,477
Location: Blackpool. UK
it should replace the first as the second is to show the selected character.

and how doesn't it work? it will help in finding why not
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to A - Z Listing with script
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13934 seconds with 12 queries