Jump to content

Recommended Posts

I'd do the following code with a loop

[code]SELECT * FROM `table` WHERE `company` LIKE 'A%' ORDER BY `company`[/code]

Just for fun, here's how I'd get started. It should print the A B C D E... thing and add hyperlinks to those that have values. It should also detect what page you're on and create an array for that letter.

[code]
if(!$_GET['letter']) $_GET['letter']="a"; // set the default page to "a"
for($i=65;$i<92;$i++) {
   $result=mysql_query("SELECT * FROM `table` WHERE `company` LIKE '".chr ($i)."%' ORDER BY `company`");
   if($_GET['letter']==chr ($i)) $myrow=mysql_fetch_assoc($result);
   echo " ";
   if (mysql_num_rows($result)>0) echo "<a href=\"thispage.php?letter=".chr ($i)."\">";
   echo strtoupper(chr ($i));
   if (mysql_num_rows($result)>0) echo "</a>";
   echo " ";
// note -- due to a forum bug, remove the spaces between chr and () in the above code.
[/code]
Link to comment
https://forums.phpfreaks.com/topic/10205-ordering-help/#findComment-38027
Share on other sites

use this query

[b][!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]select * from table order by company[!--colorc--][/span][!--/colorc--][/b]

to get it to list alphabetically. now as far as the 2nd part of your question, be more specific. Do you mean like, you wish to have A-Z printed and you click on a letter and it takes you to a new page that list the company names of that letter? if so, then your query would be more like this:

$letter = 'A'; // example letter
[b][!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]select * from table where company like '$letter%' order by company[!--colorc--][/span][!--/colorc--][/b]

but it would be like in the target php script and you would make dynamic links for each letter of the alphabet that passes $letter to the target page.

if that is not what you mean, then be more specific.
Link to comment
https://forums.phpfreaks.com/topic/10205-ordering-help/#findComment-38028
Share on other sites

[!--quoteo(post=376117:date=May 22 2006, 03:43 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 22 2006, 03:43 PM) [snapback]376117[/snapback][/div][div class=\'quotemain\'][!--quotec--]
use this query

[b][!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]select * from table order by company[!--colorc--][/span][!--/colorc--][/b]

to get it to list alphabetically. now as far as the 2nd part of your question, be more specific. Do you mean like, you wish to have A-Z printed and you click on a letter and it takes you to a new page that list the company names of that letter? if so, then your query would be more like this:

$letter = 'A'; // example letter
[b][!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]select * from table where company like '$letter%' order by company[!--colorc--][/span][!--/colorc--][/b]

but it would be like in the target php script and you would make dynamic links for each letter of the alphabet that passes $letter to the target page.

if that is not what you mean, then be more specific.
[/quote]


Spot on with my quesrtion. I am sorry that I wasn't more specific. What I want to do is have the letters a-z as links and on the page of the letter clicked, it would show the names in "company" by that letter. I just wasn't sure how to call it: '$letter%' . Thanks again guys. You both helped me.
Link to comment
https://forums.phpfreaks.com/topic/10205-ordering-help/#findComment-38125
Share on other sites

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.