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
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
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
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
When You Register, These Ads Go Away!
Old 05-10-2008, 04:58 PM Re: How can i fix this SQL select to work how i need?
vectorialpx's Avatar
Super Talker

Posts: 128
Name: irimia octavian
Location: Romania
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
__________________
my photos, my website, creation lab
vectorial pixel web services :: and, sorry for my English !

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
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
hasnt had any effect.

Dan
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
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
Webmaster Talker

Posts: 738
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
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
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
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
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
Webmaster Talker

Posts: 738
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
Eat, Sleep, Code

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

Dan
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB 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 0.14356 seconds with 12 queries