Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



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

Posts: 14
Trades: 0
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
 
 
Register now for full access!
Old 08-06-2005, 04:40 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-06-2005, 05:05 PM
dvduval's Avatar
Ultra Talker

Posts: 312
Trades: 0
That's a cool idea for my link directory script. I think I will use this. Thanks!
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
dvduval is offline
Reply With Quote
View Public Profile
 
Old 08-06-2005, 05:31 PM
andypugh's Avatar
Novice Talker

Posts: 14
Trades: 0
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
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It replaces your existing $sql= line
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-07-2005, 01:29 PM
andypugh's Avatar
Novice Talker

Posts: 14
Trades: 0
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
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to A - Z Listing with script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.27869 seconds with 12 queries