Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-13-2011, 03:48 PM   PM User | #1
Sparchy
New to the CF scene

 
Join Date: Sep 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Sparchy is an unknown quantity at this point
Event Calendar help

howdy ya,

i made myself a event calendar which works great except for one minor detail which i would like to fix. which is if 1 date lets say today's date 09/10/2011 has 3 events on it it only shows the most recent one posted.. i want it to post all 3 events..

here is what it looks like right now
http://imageshack.us/photo/my-images/854/event1.gif/

here is what i want it to kinda look like
http://imageshack.us/photo/my-images/821/event2.gif/

here is the script

PHP Code:
<html>
<head>
<style type="text/css">
a.info{
    position:relative; /*this is the key*/
    z-index:24;
    color:#FFFFFF;
    text-decoration:none}

a.info:hover{z-index:25; 
}

a.info span{display: none}

a.info:hover span{ /*the span will display just on :hover state*/
    display:block;
    position:absolute;
    padding: 9px;
    border:1px solid #FFFFFF;
    background-color:#424242; 
    color:#FFFFFF;
    font-size: 10px;
    filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=145);
    text-align: center}
</style>
</head>
<?php
$monthNames 
= Array("January""February""March""April""May""June""July""August""September""October""November""December");
$weekNames = Array("S""M""T""W""T""F""S");

if (!isset(
$_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset(
$_REQUEST["year"])) $_REQUEST["year"] = date("Y");

$cMonth $_REQUEST["month"];
$cYear $_REQUEST["year"];

$prev_year $cYear;
$next_year $cYear;
$prev_month $cMonth-1;
$next_month $cMonth+1;

if (
$prev_month == ) {
    
$prev_month 12;
    
$prev_year $cYear 1;
}
if (
$next_month == 13 ) {
    
$next_month 1;
    
$next_year $cYear 1;
}
?>
<table width="120" bgcolor="414141" cellpadding="0" Cellspacing="0">
<tr align="center">
<td bgcolor="#414141" style="color:#FFFFFF">
</td>
</tr>
<tr>
<td align="center">
<table width="100%" height="10" border="1" cellpadding="2" cellspacing="2">
<tr align="center">
<td bgcolor="#999999" style="color:#000000"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month="$prev_month "&year=" $prev_year?>" title="Previous Month" style="color:#000000"><center><b>&laquo;</b></center></a></td>
<td colspan="5" bgcolor="#999999" style="color:#000000"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear?></strong></td>
<td bgcolor="#999999" style="color:#000000"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month="$next_month "&year=" $next_year?>" title="Next Month" style="color:#000000"><center><b>&raquo;</b></center></a></td>
</tr>
<tr>
<?php
$i 
0;

foreach (
$weekNames as $v) {
echo 
"<td align='center' bgcolor='#999999' style='color:#000000'><strong>$v</strong></td>";

$i++;
}
?>
</tr> 
<?php 
$timestamp 
mktime(0,0,0,$cMonth,1,$cYear);
$maxday date("t",$timestamp);
$thismonth getdate ($timestamp);
$startday $thismonth['wday'];
$today date("j");
$currentmonth date('n');
$currentyear date("Y");

for (
$i=0$i<($maxday+$startday); $i++) {

if(
$cMonth 10){
$month_formated "0$cMonth";
}else{
$month_formated $cMonth;


if((
$i $startday 1) < 10){
$day_formated "0".($i $startday 1)."";
}else{
$day_formated = ($i $startday 1); 
}

$dato_formated "$cYear-$month_formated-$day_formated";
include 
'db.php';
$get_calendar_data mysql_query("SELECT * FROM event WHERE dates='$dato_formated'");
$count_rows mysql_num_rows($get_calendar_data);
while (
$row mysql_fetch_array($get_calendar_data)) {
$dates $row['dates'];
$events $row['events'];
$event_des $row['event_des'];
$time $row['time'];
$username $row['username'];
$filter $row['filter'];
}
if(
$count_rows 0){
if(
$filter == "event"){ 
$bgcolor "#0000FF";
}elseif(
$filter == "holiday"){
$bgcolor "0066CC";
}
$link "<a class='info' style='text-decoration:none;' href='#'>
<font color='#FFFFFF'><center>"
. ($i $startday 1) . "<span>".$events."<hr><br>".$event_des."<br><br>".$time."</span></center></font>
</a>"
;
}else{

$bgcolor "#494949";
$link "". ($i $startday 1) . "";
}

$calendar_data mysql_fetch_assoc($get_calendar_data);
$heading $calendar_data['heading']; 


if((
$i 7) == ) echo "<tr>\n";
if(
$i $startday) echo "<td></td>\n";
else
if ((
$i $startday 1) == $today && $currentmonth == $cMonth && $currentyear == $cYear)
echo (
"<td bgcolor='FF0000'><center><font color='FFFFFF'>".($i $startday 1)."</font></center></td>");
else
echo 
"
<td align='left' valign='top' height='20px' bgcolor='$bgcolor'><center>
$link
</center></td>\n"
;
if((
$i 7) == ) echo "</tr>\n";
}
?>

</table>
</td>
</tr>
</table>
the problem is at line 116 -118
which is these lines here
PHP Code:
$link "<a class='info' style='text-decoration:none;' href='#'>
<font color='#FFFFFF'><center>"
. ($i $startday 1) . "<span>".$events."<hr><br>".$event_des."<br><br>".$time."</span></center></font>
</a>"

can someone please help me

Thank you
Sparchy
Sparchy is offline   Reply With Quote
Old 09-13-2011, 04:04 PM   PM User | #2
Rowsdower!
Senior Coder

 
Rowsdower!'s Avatar
 
Join Date: Oct 2008
Location: Some say it's everything.
Posts: 2,007
Thanks: 5
Thanked 395 Times in 388 Posts
Rowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura about
I'll be honest, I'm being lazy and just posting what I think will work. I haven't tested this or done much more than look over the code you posted, but this seems like something that ought to fix the problem:

PHP Code:
$link .= "<a class='info' style='text-decoration:none;' href='#'> 
<font color='#FFFFFF'><center>"
. ($i $startday 1) . "<span>".$events."<hr><br>".$event_des."<br><br>".$time."</span></center></font> 
</a>"

All I did was add that "." right before the "=" character to append to the $link variable's value for each trip through the loop. Without that, you are overwriting the existing value on each pass through, which means you are only getting the last value from the loop.

If that doesn't work let me know and I'll get off of my butt and take a closer look.
__________________
The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
See Mediocrity in its Infancy
It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
Seek and you shall find... basically:
validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting
Rowsdower! is offline   Reply With Quote
Old 09-13-2011, 08:30 PM   PM User | #3
Sparchy
New to the CF scene

 
Join Date: Sep 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Sparchy is an unknown quantity at this point
Thanks for the reply but that didn't help it just on some of the numbers (mainly event dates) it showed the day before and the day of the event in one table row lol but it was something to try lol..

Sparchy
Sparchy is offline   Reply With Quote
Old 09-13-2011, 08:39 PM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I'm guessing too ...

The closing bracket for the while loop needs to be moved ...

Change made ....
PHP Code:
while ($row mysql_fetch_array($get_calendar_data)) {
$dates $row['dates'];
$events $row['events'];
$event_des $row['event_des'];
$time $row['time'];
$username $row['username'];
$filter $row['filter'];

if(
$count_rows 0){
if(
$filter == "event"){ 
$bgcolor "#0000FF";
}elseif(
$filter == "holiday"){
$bgcolor "0066CC";
}
$link "<a class='info' style='text-decoration:none;' href='#'>
<font color='#FFFFFF'><center>"
. ($i $startday 1) . "<span>".$events."<hr><br>".$event_des."<br><br>".$time."</span></center></font>
</a>"
;
}else{

$bgcolor "#494949";
$link "". ($i $startday 1) . "";
}

// closing bracket of while loop 

.
mlseim is offline   Reply With Quote
Old 09-13-2011, 08:45 PM   PM User | #5
Sparchy
New to the CF scene

 
Join Date: Sep 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Sparchy is an unknown quantity at this point
can't move the while bracket because all the code under that part is also needed in the while bracket as well

if needed i can put the sql in here so you guys can do some tests on it as well.
Sparchy is offline   Reply With Quote
Old 09-13-2011, 08:50 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Doesn't make sense, because right now, this is your while loop ...

while ($row = mysql_fetch_array($get_calendar_data)) {
$dates = $row['dates'];
$events = $row['events'];
$event_des = $row['event_des'];
$time = $row['time'];
$username = $row['username'];
$filter = $row['filter'];
}


I don't follow your explanation of why the bracket cannot be moved.

EDIT:
The output of the events (echo) needs to be within the while loop.
How else will it print out more than one event?


.

Last edited by mlseim; 09-13-2011 at 08:57 PM..
mlseim is offline   Reply With Quote
Old 09-13-2011, 09:01 PM   PM User | #7
Sparchy
New to the CF scene

 
Join Date: Sep 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Sparchy is an unknown quantity at this point
sorry i don't know where my mind is lol.. but if i move the bracket down it will only output just the event dates and not the calendar itself. i already tried that before a well lol..
Sparchy is offline   Reply With Quote
Old 09-13-2011, 09:25 PM   PM User | #8
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
msleim is entirely correct. Just now, what you're doing is getting a resultset of events for a date, then reassigning your variables $dates etc. inside the while loop, so that you'll only get 1 result from that while loop - the last row found from your query. Your logic isn't all there.

What you need to do, is change it. You need to find the date (already doing that) then run the query for events in that date (already doing that) THEN you need to loop through the rows using a while loop (already looping through the rows) and output the results in your desired format INSIDE the while loop. Either that, or assign results inside the while loop to an array, which isn't always the best answer and probably not the best for this method. Count rows is not needed here, and should only be used if you're wanting to output the number of events.

An example:
PHP Code:
while($row mysql_fetch_array($get_calendar_data)){
    echo 
'<div>'.$row['Somefield'].'</div>';

BluePanther is offline   Reply With Quote
Old 09-13-2011, 09:33 PM   PM User | #9
Sparchy
New to the CF scene

 
Join Date: Sep 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Sparchy is an unknown quantity at this point
i understand what you guys are saying but the way my script is set up if i put it in the while loop it will only output the event dates but not the whole calendar. i been down this road once trying to figure out how to get it to do that but its over my head lol.. if you run my script and look and edit yourself you will find out what im talking about.

here is the sql if you want to test it out
Code:
CREATE TABLE `event` (
  `id` int(25) NOT NULL default '0',
  `dates` date NOT NULL default '0000-00-00',
  `events` varchar(255) collate latin1_general_ci NOT NULL default '',
  `event_des` text collate latin1_general_ci NOT NULL,
  `time` varchar(25) collate latin1_general_ci NOT NULL default '',
  `username` varchar(255) collate latin1_general_ci NOT NULL default '',
  `filter` varchar(255) collate latin1_general_ci NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

Last edited by Sparchy; 09-13-2011 at 09:38 PM..
Sparchy is offline   Reply With Quote
Old 09-13-2011, 09:47 PM   PM User | #10
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
What I'm telling you to do is redo it with a thought about logic in your code design. Your while loop is definitely set up wrong, it is definitely giving you problems and needs changed.
BluePanther is offline   Reply With Quote
Old 09-13-2011, 10:39 PM   PM User | #11
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I would create the calendar first ...
Then, when they mouse over or click a date, pop-up the events.
That is separate from the actual calendar.


.
mlseim is offline   Reply With Quote
Old 09-13-2011, 10:41 PM   PM User | #12
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I'm old school.
Comments consume bytes of memory.
Although good to have, we were taught to compress code as much as possible.
No white space, no comments. I guess it's not 1979 anymore.


.
mlseim is offline   Reply With Quote
Old 09-13-2011, 11:51 PM   PM User | #13
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
haha wrong thread msleim . But aye, I argued that in school but got a stern 'I NEED TO BE ABLE TO READ WHAT'S GOING ON' from my teacher, who didn't actually know the language haha.
BluePanther is offline   Reply With Quote
Old 09-13-2011, 11:58 PM   PM User | #14
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
a long day ... whew ... posting in the wrong thread. I'm done for the day.
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 06:24 PM.


Advertisement
Log in to turn off these ads.