| View previous topic :: View next topic |
| Author |
Message |
PhilP Guest
|
Posted: Fri Feb 10, 2006 4:40 pm Post subject: Event in category query |
|
|
Hi,
I have a PHP script which needs to ask the question 'is this event linked to this category?'
so I have an event id and need to know if this is linked to category 16 in a situation where the etype is 26.
Is there a way to do this?
Thanks
Phil |
|
| Back to top |
|
 |
esoft_ian
Joined: 12 Sep 2005 Posts: 5275
|
Posted: Fri Feb 10, 2006 5:09 pm Post subject: |
|
|
Hi Phil,
Yup, you would do a binary and. In PHP it's:
| Code: |
| if(($event_category & 26)) |
If you want to do it from SQL, it's:
| Code: |
| select * from (thyme's table prefix)Events where id = X and (etype & 26 >= 1) |
Let me know if you have any problems. |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Feb 10, 2006 6:11 pm Post subject: |
|
|
hmmm... I suspect I'm being thick, but
if I set $event_category to the event's etype, and $cat_id to the category id, I then use
| Code: |
| if(($event_category & $cat_id)) {$checked='checked';} else {$checked="";} |
and then use $checked to preselect category checkboxes, all category checkboxes get selected.
Any ideas? |
|
| Back to top |
|
 |
esoft_ian
Joined: 12 Sep 2005 Posts: 5275
|
Posted: Fri Feb 10, 2006 6:30 pm Post subject: |
|
|
Hi Phil,
The folowing produces "checked is"
| Code: |
$event_category = 26;
$cat_id = 4;
if(($event_category & $cat_id)) {$checked='checked';} else {$checked="";}
echo("checked is $checked"); |
If I change $cat_id to 16, it says "checked is checked"
Maybe there's something else in the code that you're overlooking? |
|
| Back to top |
|
 |
PhilP Guest
|
Posted: Fri Feb 10, 2006 7:13 pm Post subject: |
|
|
Yes, entirely possible - it's been a long day.
If I do this
| Code: |
$event_category = 26;
$cat_id = 4;
if(($event_category & $cat_id)) {$checked='checked';} else {$checked="";}
|
it works.
But if I use a $event_category value which is returned from a query, where the value is 26, it doesn't work.
Driving me nuts. It may be time to go to the pub instead... |
|
| Back to top |
|
 |
PhilP Guest
|
Posted: Fri Feb 10, 2006 7:23 pm Post subject: |
|
|
But it turns out that if I do this
| Code: |
| $event_category = $event_category * 1; |
it works.
Bizarre. |
|
| Back to top |
|
 |
esoft_ian
Joined: 12 Sep 2005 Posts: 5275
|
Posted: Fri Feb 10, 2006 7:38 pm Post subject: |
|
|
| Ahh.. PHP must be think that it's a string. When you * 1, it converts it to an integer. |
|
| Back to top |
|
 |
|