SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 15th, 2002, 12:05 AM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
sortby?

How would I be able to sort info by letter? ie, when you visit the page, it shows the last 5 updates, but when click a letter to sort it by, like A, it just shows the topics that start with A.

Reply With Quote
  #2  
Old June 15th, 2002, 12:55 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: sortby?

:-/

..put yer topics in an array and use the sort function.

Reply With Quote
  #3  
Old June 15th, 2002, 01:53 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: sortby?

if you are pulling from a database :

SELECT * FROM TABLE WHERE field LIKE 'A%' OR field LIKE 'a%' ORDER BY field


Reply With Quote
  #4  
Old June 15th, 2002, 02:17 AM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: sortby?

Could I do that like this:

php Code:
Original - php Code
  1.  
  2. if('$action' == 'sortby' )
  3. {
  4. $result = mysql_query("SELECT * FROM interdb ORDER BY '%' LIMIT 5",$db);
  5. while($myrow = mysql_fetch_array($result))
  6. }
  7.  
  8. else()
  9. {
  10. $result = mysql_query("SELECT * FROM interdb ORDER BY id desc LIMIT 5",$db);
  11. while($myrow = mysql_fetch_array($result))
  12. }

Reply With Quote
  #5  
Old June 15th, 2002, 08:40 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: RE: sortby?


Quote:
php Code:
Original - php Code
  1.  
  2. if('$action' == 'sortby' )
  3. {
  4. $result = mysql_query("SELECT * FROM interdb ORDER BY '%' LIMIT 5",$db);
  5. while($myrow = mysql_fetch_array($result))
  6. }


I am not quite sure what the above snipplet is suppose to do, however Matt led you in the right direction.

I am assuming you want your result to include only topics that start with "A" but you probably also want them sorted by date. You are, of course, going to want to pass your script the char to sort by.

Try something like this:

select * from table where TOPIC_FIELD like '".strtoupper($char)."%' or TOPIC_FIELD like '".strtolower($char)."%' order by DATE_FIELD desc

Hope that helps.

Reply With Quote
  #6  
Old June 18th, 2002, 12:19 AM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: sortby?

I haven't been able to try this for a few days due to my server being down, but I get an unexpected T string on it

php Code:
Original - php Code
  1.  
  2. if('$action' == 'sortby')
  3. {
  4. $result = mysql_query("select * from interdb ORDER BY bandname like '".strtoupper($char)."%'" LIMIT 5,$db);
  5. while($myrow = mysql_fetch_array($result))
  6. {
  7. echo( "<p><b><a href=vinter.php?id=" .$myrow[id]. " class=link>" . $myrow['bandname'] . "</a></b> <font class=rm>- " . date("F j", strtotime($myrow['date'])) . "</font>" );
  8. echo( "<br>" . $myrow['preinter'] );
  9. echo( "<br><b><font class=rm><a href=vinter.php?id=" .$myrow[id]. " class=rm>...Read More</a></b></font>" );
  10. }
  11. }
  12. else()
  13. {
  14. $result = mysql_query("SELECT * FROM interdb ORDER BY id desc LIMIT 5",$db);
  15. while($myrow = mysql_fetch_array($result))
  16. {
  17. echo( "<p><b><a href=vinter.php?id=" .$myrow[id]. " class=link>" . $myrow['bandname'] . "</a></b> <font class=rm>- " . date("F j", strtotime($myrow['date'])) . "</font>" );
  18. echo( "<br>" . $myrow['preinter'] );
  19. echo( "<br><b><font class=rm><a href=vinter.php?id=" .$myrow[id]. " class=rm>...Read More</a></b></font>" );
  20. }
  21. }

Reply With Quote
  #7  
Old June 18th, 2002, 02:32 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: sortby?

In your first query:

$result = mysql_query("select * from interdb ORDER BY bandname like '".strtoupper($char)."%'" LIMIT 5,$db);

You need to take out the " that is before LIMIT. So it should look like this:

$result = mysql_query("select * from interdb ORDER BY bandname like '".strtoupper($char)."%' LIMIT 5,$db);

That is the first thing to check, Then rerun the code and see if there is any other lines w/errors. When debugging you want to use a top-down approach, many times when fixing errors/warnings on line 1 will also clear line errors/warning in latter lines.

Hope that helps.

Reply With Quote
  #8  
Old June 18th, 2002, 02:34 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: sortby?

Forgot this part. After removing the " before the LIMIT you need to place it after the 5. It should look like this:

$result = mysql_query("select * from interdb ORDER BY bandname like '".strtoupper($char)."%' LIMIT 5",$db);

Sorry.

Reply With Quote
  #9  
Old June 19th, 2002, 12:27 AM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: sortby?

now I'm getting this phrase error

Parse error: parse error, unexpected ')' in /home/gmflp/public_html/test.php on line 28

which is the line

echo( "<br><b><font class=rm><a href=vinter.php?id=" .$myrow[id]. " class=rm>...Read More</a></b></font>" );

Reply With Quote
  #10  
Old June 19th, 2002, 02:29 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: sortby?

That line of code is used twice. Is it the first instance or the second?

Reply With Quote
  #11  
Old June 19th, 2002, 02:35 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: sortby?

On a side note, echo does not require an open paren ( and a close paren ).

echo "some text"; // legal
echo "text".$foo; // legal
echo "text".$foo."text"; // legal
echo $foo."text"; // legal
echo $foo; // legal

Reply With Quote
  #12  
Old June 19th, 2002, 10:06 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: sortby?

now I'm getting this error, thanks for your help by the way

Parse error: parse error, unexpected '{' in /home/gmflp/public_html/test.php on line 30

Reply With Quote
  #13  
Old June 20th, 2002, 02:16 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: sortby?

Not knowing what the rest of your code looks like, I can't tell you where exactly the problem is. However, I can tell you that the error means that you do not have an equal amount of {'s and }'s.

I would sugesst going thru your code and matching every open { with its closing }. This is where your personal programming style comes into play. Personally, and I believe this to be true "industry wide", is that after every { I indent two spaces so that everything lines up nice and neat on the left hand side.

That should sort of help.

Reply With Quote
<