Current location: Hot Scripts Forums » Programming Languages » PHP » Problem: MySQL Querry and Result


Problem: MySQL Querry and Result

Reply
  #1 (permalink)  
Old 02-14-06, 05:57 PM
nitro4file nitro4file is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Problem: MySQL Querry and Result

Hi everyone,

i have two little issues,

1. hv got a table with
ID| USER | COUNTRY | DATE | TIME |ect

I querry sql to get list of country to display in a drop down(to be selected later on), so far it's okay but the problem is that i have 6,15, or 20 times same country if there is 20,15,6 users from that country, what i want to do is get only 1 and this regarless of the number of entry for that country, can't figure out what the SQL querry should be. i try group id by hash but no success.

2. Need to display result just before the last result.

i fetch result from sql ORDER BY id DESC, so far it's okay, but what i need is just before the last result, e.g if there is 30 i need 29, 100 i need 99, etc

can you give me an idea how to handle that?

Thanks for your help

Nitro
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-14-06, 06:26 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
For your first problem, try something like this -
SELECT DISTINCT country FROM table
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-15-06, 12:14 AM
nitro4file nitro4file is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Mab,

I try SELECT DISTINCT but it shows some double or trible entries from some countries particularly those in between other countries e.g

USA>
USA>> Those are shows only 1 USA (thats good)
USA>
CANADA
USA> Those are listed
USA> Those are listed
FRANCE

any idea?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-15-06, 01:24 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
...Part 2. I think the 1st version finds the distinct rows in groups in the order they are in the database. Try this with the ORDER BY -

SELECT DISTINCT(country) FROM table ORDER BY country
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 02-15-06, 02:00 AM
nitro4file nitro4file is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
That's work perfectly,

Thanks Buddy, Two thumb up!

Any idea about displaying the entry just before the last entry? Part 1??

Cheers
Nitro
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 02-15-06, 12:59 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Since your results are in an array, I think you can use the end(); statement to set the array pointer to the last element, then prev(); to point to the previous and return the array value to get the record you want.

http://www.php.net/manual/en/function.end.php
http://www.php.net/manual/en/function.prev.php
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 02-16-06, 09:00 AM
Nebulous Nebulous is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
the way i would have build the sql structure is by having a seperate table for each country.

which would look like:

| Country | id |

then in the existing table instead of just using the country, use the ID...

Yes, its a few more lines of codes, but allows you to have more flexibility.

Nebulous.
__________________
AtomicPHP
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab data from mysql resualt and How to make this eregi work ? websnow PHP 12 01-08-05 01:44 PM


All times are GMT -5. The time now is 01:13 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.