xoops forums

sarahmx

Quite a regular
Posted on: 3/6 3:49
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 371
Since: 2007/10/28
#1

extcal database query

Hello XOOPSian

can you help me with this query

i would like to show todays event manually using the query below outside of xoops..currently testing this in localhost inside XOOPS

event_start is stored as integer eg 1306112400

$time time(); 
//echo $time;
$today=date("d/m/Y"strval($time));
//echo $today;

global  $xoopsDB;
$sql "SELECT * FROM " $xoopsDB->prefix('extcal_event') . "  WHERE DATE_FORMAT(event_start, '%d/%m/%Y')='$today' ORDER BY event_start";


The code is not working at the moment, can you guys help me..Please

Bleekk

Theme Designer
Posted on: 3/6 6:43
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 809
Since: 2002/12/14
#2

Re: extcal database query

Maybe you can try something like this
$time time();  
$today date("d/m/Y"strval($time)); 

global  
$xoopsDB
$result $xoopsDB->query("SELECT * FROM " $xoopsDB->prefix('extcal_event') );
if (
$result===false) {
    die(
$xoopsDB->error()); 

while (
$row $xoopsDB->fetchArray($result)) { 
    if ((
date('d/m/Y'$row['event_start'])) == $today){
      echo 
$row['event_title'];
    }
}

sarahmx

Quite a regular
Posted on: 3/6 20:22
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 371
Since: 2007/10/28
#3

Re: extcal database query

Thank you its working bleek..i added event_end also

if ((date('d/m/Y'$row['event_start'])) == $today OR (date('d/m/Y'$row['event_end'])) == $today){


but if i have 3 days event

let say 1/3 to 3/3 and today is 2/3 how should i change my code to display the event for 2/3

sarahmx

Quite a regular
Posted on: 3/6 23:30
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 371
Since: 2007/10/28
#4

Re: extcal database query

i tried it something like this but its not working

$time time(); 
$today=date("d/m/Y"strval($time));


global  
$xoopsDB;
$sql "SELECT * FROM " $xoopsDB->prefix('extcal_event') . " "
if (
$result===false) { 
    die(
$xoopsDB->error());  

$result $xoopsDB->query($sql); 

while(
$row=$xoopsDB->fetchArray($result)) {
$event_title $row['event_title']; 
$event_start=date("d/m/Y"strval($row["event_start"]));
$event_end=date("d/m/Y"strval($row["event_end"]));

//if ((date('d/m/Y', $row['event_start'])) == $today OR (date('d/m/Y', $row['event_end'])) == $today){ 

if ($event_start <= $today  && $today <= $event_end){ 
 echo 
$row['event_title']; 
    } 
}

zyspec

Module Developer
Posted on: 3/7 0:41
zyspec
zyspec (Show more)
Module Developer
Posts: 986
Since: 2004/9/21
#5

Re: extcal database query

I think what you want is to replace the last 3 lines with the following:

if ($row['event_start'] <= $time && $time <= $row['event_end']) { 
  echo 
$row['event_title']; 
}


This compares the numeric value of today, the starting time and the ending time. Your previous attempt compares the formatted date string, which isn't what you want.

sarahmx

Quite a regular
Posted on: 3/7 1:12
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 371
Since: 2007/10/28
#6

Re: extcal database query

Thank you zyspec...all now is working



$time time();  
$today=date("d/m/Y"strval($time)); 


global  
$xoopsDB
$sql "SELECT * FROM " $xoopsDB->prefix('extcal_event') . " ";  
if (
$result===false) {  
    die(
$xoopsDB->error());   
}  
$result $xoopsDB->query($sql);  

while(
$row=$xoopsDB->fetchArray($result)) { 
$event_title $row['event_title'];  
$event_start=date("d/m/Y"strval($row["event_start"])); 
$event_end=date("d/m/Y"strval($row["event_end"])); 

//if ((date('d/m/Y', $row['event_start'])) == $today OR (date('d/m/Y', $row['event_end'])) == $today){  

if ($event_start == $today OR $event_end==$today OR $row['event_start'] <= $time && $time <= $row['event_end']){ 
 echo 
$row['event_title'];  
    }  
}

Bleekk

Theme Designer
Posted on: 3/7 2:12
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 809
Since: 2002/12/14
#7

Re: extcal database query

you need to change the order of the first part of your code to this
global  $xoopsDB;  
$sql "SELECT * FROM " $xoopsDB->prefix('extcal_event') . " ";   
$result $xoopsDB->query($sql);
if (
$result===false) {   
    die(
$xoopsDB->error());    
}

sarahmx

Quite a regular
Posted on: 3/7 21:58
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 371
Since: 2007/10/28
#8

Re: extcal database query

noted and tq Bleek