Jump to content

Recommended Posts

I have this script working that lists A-Z links and i want to show just a # sign for the number range but no matter how I try to echo just one # to represent the 0-9 range it gives me 9 #'s

                     $letter = isset($_GET['letter']) ? $_GET['letter'] :"A";


                                                       
                                                        //alphabetical pagination links
                                                        echo '<div align="center"><b>';
                                                        foreach(range('A','Z') as $c){
                                                          ($letter == $c)
                                                            ? printf('%s&nbsp',$c)
                                                            : printf('<a href="?letter=%s">%s</a> ',$c,$c);
                                                        }
                                                        //Other
                                                         foreach(range('0','9') as $n){
                                                          ($letter == $n)
                                                        ? printf('%s&nbsp',$n)
                                                        : printf('<a href="?letter=%s">#</a> ',$n);
                                                        }
                                                    
                                                        echo "</b><br></div><p>";
                                                        
                                                        //Show all restaurants that start with $letter  not between "A" and "Z"
                                                          //Show all restaurants that start with $letter
                                                        $sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE name LIKE '{$letter}%'";
                                                        $result = mysql_query($sql) or die(mysql_error());
                                                        while($row = mysql_fetch_assoc($result)){
                                                            
                                                            
                                                            $name = $row['name'];
                                                            
                                                          printf(
                                                                        '<a href="view.php?ID=%s"><b>%s</b><br />%s<br /><br /></a>',
                                                                        $row['ID'],  
                                                                        $row['name'],
                                                                        $row['address']
                                                                );
                                                            
                                                        }
                                                      
                                                      echo $row;

Link to comment
https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/
Share on other sites

Yep I caught onto that too...boss thought it would look better to have the A-Z and not 0-9 just a # for numbers but some of the names in the db start with different numbers so a user needs the numerical links...think this is a boss error ...lol ..there is another problem is I don't want it to always default back to "A" on the display pages...because then it outputs the selected results at the bottom of the A list....but when I try and play with this line

   $letter = isset($_GET['letter']) ? $_GET['letter'] :"A";

by replacing the "A" with "" ...then none of the links work.... ideas?

I think it has to have 0 1 2 3 4 etc so a user can choose what to view for instance they want to check out a restaurant called "821" then they have to be able to see an 8 to click...the bigger problem is getting it to not show the default "a" listings on the top of the results....if you click on say "applebees" it outputs the details for that inspection UNDER all the "A's" I want that to go away when viewing details..without having to make another page hopefully...right now it just loads the details in this page...

ok to sum it up it evaluates whether the letter A is set if it is it displays all Letter A restaurants.

 

 

so we could do something like

 

 <?php
$letter = isset($_GET['letter']) ? $_GET['letter'] :range('A','Z');
?>

 

which should display all restaurants A-Z and not just A by default  :)

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.