CodeMama Posted July 26, 2009 Share Posted July 26, 2009 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 ',$c) : printf('<a href="?letter=%s">%s</a> ',$c,$c); } //Other foreach(range('0','9') as $n){ ($letter == $n) ? printf('%s ',$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; Quote Link to comment https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/ Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 Why do you even use the array if all you want to do is print one single link...? Or am I missing something? Quote Link to comment https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/#findComment-883228 Share on other sites More sharing options...
darkfreaks Posted July 26, 2009 Share Posted July 26, 2009 she wants to grab the range of 0-9 to do that you must use a loop. anyhow i dont get how this works really with your code. it looks like it displays a link with # Quote Link to comment https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/#findComment-883248 Share on other sites More sharing options...
CodeMama Posted July 26, 2009 Author Share Posted July 26, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/#findComment-883253 Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 Do I get you right now. You wish to display ONE link (using #) if you are not on 0-9 and you wish to simply display # if you are on 0-9? If so, simply use in_array(). Quote Link to comment https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/#findComment-883256 Share on other sites More sharing options...
CodeMama Posted July 26, 2009 Author Share Posted July 26, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/#findComment-883275 Share on other sites More sharing options...
darkfreaks Posted July 26, 2009 Share Posted July 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/#findComment-883418 Share on other sites More sharing options...
darkfreaks Posted July 26, 2009 Share Posted July 26, 2009 or better yet you could do <?php $letter = isset($_GET['letter']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/#findComment-883431 Share on other sites More sharing options...
Philip Posted July 26, 2009 Share Posted July 26, 2009 or better yet you could do <?php $letter = isset($_GET['letter']); ?> Umm... that would just return true/false and wouldn't grab the letter the user wants. Quote Link to comment https://forums.phpfreaks.com/topic/167497-sort-repeating-a-range-in-echo/#findComment-883438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.