Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How can i fix this SQL select to work how i need?
Old 05-10-2008, 04:39 PM How can i fix this SQL select to work how i need?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Hi,

On http://calmcharity.org/events.php it shows the next event in a yellow box at the top.

This is the code:
PHP Code:
$cur_datetime date('Y-m-d H:is');
if(
$rank >= 5)
{
$where "type='1' OR type='2' OR type='3' OR type='4'";
}
elseif(
$rank >= 4)
{
$where "type='1' OR type='2' OR type='3'";
}
elseif(
$rank >= 3)
{
$where "type='1' OR type='2'";
}
else
{
$where "type='1'";
}
$next_event_res $db->query("SELECT * FROM events WHERE date > '$cur_datetime'  AND $where ORDER BY date ASC LIMIT 1"); 
now $rank is users rank which goes from 1 - 3
1 = admin
2 = committee
3 = normal member

and then you have the type on the events
which goes

1 = public (shows to all without login)
2 = requires basic account
3 = family acct
4 = committee
5 = admin.

And this is suposed to do it so if im logged in as admin and the nearest event is a admin/committee/family/public event will show

if logged in as committee and nearest event is committee/family/public

if family shows family/public

BUT. when your not logged in it shows the latest public event as it should.

BUT if your logged in it shows the earliest event for your rank.

so if admin it shows the very first admin event if committee shows the very first committee meeting.

WHY!?

how can i fix this? :s thanks,

TP for working answer
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 05-10-2008, 04:58 PM Re: How can i fix this SQL select to work how i need?
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
try "SELECT * FROM `events` WHERE `date` > '$cur_datetime' AND $where ORDER BY `date` ASC LIMIT 1"

and... make it with a limit of 10 or 12, to see some results... if the order is ok
__________________
you can
Please login or register to view this content. Registration is FREE

Last edited by vectorialpx; 05-10-2008 at 04:59 PM..
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 05-10-2008, 05:54 PM Re: How can i fix this SQL select to work how i need?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
hasnt had any effect.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-10-2008, 06:13 PM Re: How can i fix this SQL select to work how i need?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
I'm not quite sure if I understand what's not working...is it not displaying them in the right order? You can order by more than one field if you need to. If you want to display by type first and then order that by date, you would write ORDER BY type DESC date ASC.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-10-2008, 06:18 PM Re: How can i fix this SQL select to work how i need?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
well it shouldnt order by type at all, so the type should just select what events are avalible and then for it to select the one which is the next event and show that.

It appears that when your not logged in (so type='1') it is orderd as i expected and shows the next event but when i have more (your logged in) and you have type='1' OR type='2' ... etc it seems to reverse them so the next event is the bottom one :S
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-10-2008, 06:58 PM Re: How can i fix this SQL select to work how i need?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Try switching it to DESC rather than ASC and see what happens. I'm not sure how many test events you have, but if you only have one for type=1, that could be what is causing the problem.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-10-2008, 07:11 PM Re: How can i fix this SQL select to work how i need?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Ok this is random but it seems like its working now >< no clue why

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to How can i fix this SQL select to work how i need?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.09431 seconds with 12 queries