Solved

Displaying Little Calendar of records on page

Posted on 2013-01-23
39
297 Views
Last Modified: 2013-01-24
Hi everyone,

I have a page that displays the records of user’s journal and would like to add a little calendar similar to what I have attached. As you can see, the calendar shows a little indicator on the dates there is a record present and you can click on it and it will take you to that particular record. Could anyone help me in setting something up like this. I could do all the CSS stuff and I have all the records fetching correctly from the DB. I just don’t know how to display them in a calendar format

I can post more of the code that we're  using if it's helpful:

$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' ORDER BY entry_id DESC")

Open in new window


Thanks for your help,

Derek
calendar.jpg
0
Comment
Question by:TLN_CANADA
  • 21
  • 18
39 Comments
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38811626
This should get you started
<?php

// $query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' ORDER BY entry_id DESC")

$cal = array();

$cal['20121109'] = 'some event';

//$t = time(); echo $t.' / '.date('Ymd', $t).' / '.date('Ymd', $t - 86400).'<br><br>';

if (isset($_GET['c']) && preg_match('/^\d{6}$/', $_GET['c']) === 1) { //strlen($_GET['c']) == 6 && 
	$day1 = getdate(date_create_from_format('Ymd', $_GET['c'].'01')->getTimestamp());
} else {
	$day1 = getdate();
	$day1 = getdate(time() - ($day1['mday'] - 1) * 86400); // first of current month
}
//echo '<pre>';
//print_r($day1);
//echo '</pre>';

?>
<html>
<head>
<title> EE Q_28005952 </title>
<style type="text/css">
table.evt {
	font-family: verdana;
	font-size: 8pt;
}
table.evt td {
	text-align: center;
}
table.evt td.nrm { /* normal */
	background-color: silver;
}
table.evt td.out { /* outside curent month */
	background-color: gray;
}
table.evt td.evt { /* event */
	color: blue;
	/* and/or attach 'blue triangle' image here */
}
</style>
</head>
<body>
<?

echo '<table border=1 class="evt">';

echo '<tr>';
echo '<td align="left">';
echo '<a href="?c='.clink($day1['year'], $day1['mon']-1).'">&lt;</a>';
echo '</td>';
echo '<td colspan=5>';
echo $day1['month'].' '.$day1['year'];
echo '</td>';
echo '<td align="right">';
echo '<a href="?c='.clink($day1['year'], $day1['mon']+1).'">&gt;</a>';
echo '</td>';
//echo '</tr>'; // done first time in the loop...

$cday = $day1[0] - $day1['wday'] * 86400; // start at last sunday // TODO: when month (feb) has only 28 days and starts on sunday, go 7 days back?

for ($d = 0; $d < 42; $d++) {
	if ($d % 7 == 0) {
		echo '</tr>' . PHP_EOL;
		echo '<tr>';
	}
	$a = getdate($cday);
	$cls = ($a['mon'] == $day1['mon']) ? 'nrm' : 'out';
	$t = "";
	if (isset($cal[date('Ymd', $cday)])) {
		$cls .= ' evt';
		$t = ' title="'.$cal[date('Ymd', $cday)].'"';
	}
	echo '<td class="'.$cls.'"'.$t.'>'.$a['mday'].'</td>';
	$cday += 86400;
}
echo '</tr>' . PHP_EOL;

echo '</table>';

function fixzero($n) {
	return ($n < 10 ? '0' : '').$n;
}

function clink($y, $m) {
	if ($m == 0) {
		$m = 12;
		$y--;
	} elseif ($m == 13) {
		$m = 1;
		$y++;
	}
	return $y.fixzero($m);
}

?>
</body>
</html>

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38811706
Some more explanation: from your query you should set the appropriate elements in the $cal array.

If you don't want to refresh your whole page then you could use ajax load() to just load this table.

On both counts I would need some more info if you need help with that.
0
 

Author Comment

by:TLN_CANADA
ID: 38811894
Absolutely, thank you Robert. Here is the complete file we are using that retrieves the user's journal records from the database and then displays them on the page. If you could show me how to integrate your code into what we already have that would be amazing!

 
<?php	

// Connecting to the DB
	mysql_connect('xxx','foxdbmain','xxx!') or die ( mysql_error() );
	mysql_select_db("foxdbmain") or die ( mysql_error() );

	$username = Phpfox::getUserBy('full_name');


	
	$pic_abs = Phpfox::getUserBy('user_image');
	$pic_abs = str_replace("%s","",$pic_abs);
	
	if ( $pic_abs == NULL )
	{
		$URL = "http://www.clearthemirror.com/theme/frontend/default/style/default/image/noimage/profile_50.png";
	}
	else
	{
		$URL = "http://www.clearthemirror.com/file/pic/user/" . "$pic_abs";
	}
	
?>
<style type = "text/css">
html,body{
	width:100%;
	height:100%;
	margin:0px;
	padding:0px;
}
div {
	margin: 0;
	padding: 0;
}
body {
	background-color: white;
}
div#HeaderTitle {
	float: left;
	width: 50%;
	text-align: left;
	height: 24px;
}
div#HeaderButton {
	float: right;
	width: 50%;
	text-align: right;
	height: 24px;
}
.ClearFloat {
	clear: both;
}
.Seperator {
	margin-top: 5px;
	margin-bottom: 5px;
}
#BarSearch {
	float: left;
	width: 50%;
	text-align: left;
	height: 24px;
}
#BarAction {
	float: right;
	width: 50%;
	text-align: right;
	height: 24px;
}
#Side {
	float: left;
	position: relative;
	width: 10%;
	height: 100%;
	text-align: center;
	margin-left: 5px;
}
#Journal {
	float: right;
	position: relative;
	width: 88%;
	height: 100%;
}
#Journal p {
	margin-top: 0px;
}
#Journal_Title {
	font-weight: bold;
}
#Entry_Date {
	text-align: center;
}
#Entry_Month {
    border: 1px solid black;
    border-radius: 10px 10px 10px 10px;
    font-size: 14px;
    height: 25px;
    line-height: 25px;
    background: -moz-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	background: -webkit-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
    font-weight: bold;	
}
#Entry_Day {
	background: -moz-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	background: -webkit-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	font-size: 35px;
	font-weight: bold;
}
</style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<div id = "Wrapper">
	<div id = "Header">
		<div id = "HeaderTitle">Search Journals:</div>
		<div id = "HeaderButton"><input type = "button" value = "New Journal" target="_blank" onClick = "location.href = 'http://www.clearthemirror.com/index.php?do=/clearthemirror/newjournal/'"/></div>
		<div class = "ClearFloat"></div>
	</div>
		<div class = "Seperator"><hr></div>
	<div id = "Bar">
		<div id = "BarSearch">
			<form method = "POST"><input type = "text" name = "search_journal" value = "Search Journals ..." onClick = "this.value = '';"/><input type = "submit" value = "GO"/></form>
		</div>
		<div id = "BarAction"><form method = "POST">Show The Last <select name = "FilterRow"><option value = "5">5</option><option value = "10">10</option><option value = "20">20</option><option value = "all">All</option></select><input type = "submit" value = "GO"/> Items</form></div>
		<div class = "ClearFloat"></div>
	</div>
		<div class = "Seperator"><hr></div>

		<?php
			if ( ! isset($_POST["search_journal"]) )
			{
								$select_all = false;
								
								if ( ! isset($_POST["FilterRow"]) )
								{
									$limit = 5; // default
								}
								else if ( $_POST["FilterRow"] == "all" )
								{
									$select_all = true;
								}
								else
								{
									$limit = (int)$_POST["FilterRow"];
								}
								
								if ( $select_all )
								{
									$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' ORDER BY entry_id DESC") or die ( mysql_error() );
								}
								else
								{
									$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' ORDER BY entry_id DESC LIMIT $limit") or die ( mysql_error() );
								}
								
								$total_things = mysql_num_rows($query);
								
								if ( $total_things == 0 )
								{
									echo "You do not seem to have posted any journal! Why don't you start? :) ";
								}
								else
							{
								while ( $row = mysql_fetch_array($query) )
								{
								$post_id = $row["entry_id"];
								$date = $row["entry_timestamp"];
								$day = date('d',strtotime($date));
								$month = date('F',strtotime($date));
								?>
						<div id = "Content">
										<div id = "Side">
												<div id = "Entry_Month"><?php echo $month; ?></div>
												<div id = "Entry_Day"><?php echo $day; ?></div>									
											<img height = "70px" width = "50px" src = "<?php echo $URL; ?>">
										</div>
										<div id = "Journal">
											<p id = "Journal_Title"><?php echo $row["entry_title"]; ?></p>
											<p id = "Journal_Sender"><?php echo "By: " . $username; ?></p>
											<p id = "Journal_Content"><?php echo $row["entry_text"];?></p>
											<div class = "Seperator"><hr></div>
											<p id = "Journal_Timestamp"><?php echo $date . " - <a href = 'editjournal.php?id=$post_id'>Edit</a> - <a href = 'deletejournal.php?id=$post_id'>Delete</a>";?></p>
										</div>
						<div class = "ClearFloat"></div>
						<div class = "Seperator"><hr></div>
						</div>
								<?php
								}
							}			
			}
			else
			{
								$term = $_POST["search_journal"];
			
								$query = mysql_query("SELECT * FROM journal_table WHERE entry_text LIKE '%$term%' OR entry_title LIKE '%$term%' ORDER BY entry_id DESC") or die ( mysql_error() );
								
								$total_things = mysql_num_rows($query);
								
								if ( $total_things == 0 )
								{
									echo "No Result For The Term Selected.<br><br>";
								}
								else
							{
								while ( $row = mysql_fetch_array($query) )
								{
								$post_id = $row["entry_id"];
								?>
						<div id = "Content">
										<div id = "Journal" style = "width: 100%;">
											<p id = "Journal_Title"><?php echo $row["entry_title"]; ?></p>
											<p id = "Journal_Sender"><?php echo "By: " . $row["user_id"]; ?></p>
											<p id = "Journal_Content"><?php echo $row["entry_text"];?></p>
											<div class = "Seperator"><hr></div>
											<p id = "Journal_Timestamp"><?php echo $row["entry_timestamp"] . " - <a href = 'editjournal.php?id=$post_id'>Edit</a> - <a href = 'deletejournal.php?id=$post_id'>Delete</a>";?></p>
										</div>
						<div class = "ClearFloat"></div>
						<div class = "Seperator"><hr></div>
						</div>
								<?php
								unset($_POST["search_journal"]);
								}
							}				
			}
			

		?>
</div> <!-- end of Wrapper -->
</body>
</html>

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38812046
Could you either:

1 - also post the generated html

2 - put this in a test page on your website that doesn't require logging in

3 - provide a test login and password
0
 

Author Comment

by:TLN_CANADA
ID: 38812078
Sure thing, here is the html generated:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<style type = "text/css">
html,body{
	width:100%;
	height:100%;
	margin:0px;
	padding:0px;
}
div {
	margin: 0;
	padding: 0;
}
body {
	background-color: white;
}
div#HeaderTitle {
	float: left;
	width: 50%;
	text-align: left;
	height: 24px;
}
div#HeaderButton {
	float: right;
	width: 50%;
	text-align: right;
	height: 24px;
}
.ClearFloat {
	clear: both;
}
.Seperator {
	margin-top: 5px;
	margin-bottom: 5px;
}
#BarSearch {
	float: left;
	width: 50%;
	text-align: left;
	height: 24px;
}
#BarAction {
	float: right;
	width: 50%;
	text-align: right;
	height: 24px;
}
#Side {
	float: left;
	position: relative;
	width: 10%;
	height: 100%;
	text-align: center;
	margin-left: 5px;
}
#Journal {
	float: right;
	position: relative;
	width: 88%;
	height: 100%;
}
#Journal p {
	margin-top: 0px;
}
#Journal_Title {
	font-weight: bold;
}
#Entry_Date {
	text-align: center;
}
#Entry_Month {
    border: 1px solid black;
    border-radius: 10px 10px 10px 10px;
    font-size: 14px;
    height: 25px;
    line-height: 25px;
    background: -moz-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	background: -webkit-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
    font-weight: bold;	
}
#Entry_Day {
	background: -moz-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	background: -webkit-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	font-size: 35px;
	font-weight: bold;
}
</style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<div id = "Wrapper">
	<div id = "Header">
		<div id = "HeaderTitle">Search Journals:</div>
		<div id = "HeaderButton"><input type = "button" value = "New Journal" target="_blank" onClick = "location.href = 'http://www.cleartm.com/index.php?do=/clearthemirror/newjournal/'"/></div>
		<div class = "ClearFloat"></div>
	</div>
		<div class = "Seperator"><hr></div>
	<div id = "Bar">
		<div id = "BarSearch">
			<form method = "POST"><input type = "text" name = "search_journal" value = "Search Journals ..." onClick = "this.value = '';"/><input type = "submit" value = "GO"/></form>
		</div>
		<div id = "BarAction"><form method = "POST">Show The Last <select name = "FilterRow"><option value = "5">5</option><option value = "10">10</option><option value = "20">20</option><option value = "all">All</option></select><input type = "submit" value = "GO"/> Items</form></div>
		<div class = "ClearFloat"></div>
	</div>
		<div class = "Seperator"><hr></div>

								<div id = "Content">
										<div id = "Side">
												<div id = "Entry_Month">January</div>
												<div id = "Entry_Day">23</div>									
											<img height = "70px" width = "50px" src = "http://www.cleartm.com/file/pic/user/2012/11/827a5bffd1e37c2616c48f7655231b30.jpg">
										</div>
										<div id = "Journal">
											<p id = "Journal_Title">Another test </p>
											<p id = "Journal_Sender">By: John Shea</p>
											<p id = "Journal_Content">Hello. <br></p>
											<div class = "Seperator"><hr></div>
											<p id = "Journal_Timestamp">2013-01-23 13:36:09 - <a href = 'editjournal.php?id=63'>Edit</a> - <a href = 'deletejournal.php?id=63'>Delete</a></p>
										</div>
						<div class = "ClearFloat"></div>
						<div class = "Seperator"><hr></div>
						</div>
														<div id = "Content">
										<div id = "Side">
												<div id = "Entry_Month">December</div>
												<div id = "Entry_Day">21</div>									
											<img height = "70px" width = "50px" src = "http://www.cleartm.com/file/pic/user/2012/11/827a5bffd1e37c2616c48f7655231b30.jpg">
										</div>
										<div id = "Journal">
											<p id = "Journal_Title">Test</p>
											<p id = "Journal_Sender">By: John Shea</p>
											<p id = "Journal_Content">Dere<br></p>
											<div class = "Seperator"><hr></div>
											<p id = "Journal_Timestamp">2012-12-21 12:02:20 - <a href = 'editjournal.php?id=44'>Edit</a> - <a href = 'deletejournal.php?id=44'>Delete</a></p>
										</div>
						<div class = "ClearFloat"></div>
						<div class = "Seperator"><hr></div>
						</div>
								</div> <!-- end of Wrapper -->
</body>
</html>

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38812245
Ah, my mistake, I thought it might make it clear where you want the calendar but I guess I just should have asked. Another option would be to make it into an include file, or just a function that you can call at any point in the page. Does that sound like a solution you could work with?

Either way, the important thing is that you fill the array with events so that the code can display them. Something like this:
$cal = array();
while ( $row = mysql_fetch_array($query) )
{
$post_id = $row["entry_id"];
$date = $row["entry_timestamp"];
$cal[date('Ymd',strtotime($date))] = 'some event';

Open in new window


Now the next question is going to be, which events you want to show in the calendar? It seems natural they are only the ones in the selected month, but what happens when searching or restricting to 5 items? Too little events will be shown so you may need a separate database query and loop to avoid that.
0
 

Author Comment

by:TLN_CANADA
ID: 38812272
Yes, thank you. I would like this little calendar in a side bar and have it displays all the records for the month in it and as you mentioned, the ability to click back and forth between different months would be great. I guess it will be necessary to setup a separate query for this. I wanted to send you this so you'd see exactly how we're doing it at the moment.

Actually if we could have it in a separate include file that would be ideal.

Thank you so much!,

D
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38812520
Ok, with the attached include file, on your page you could do:
<div id="cal"><? showcal() ?></div>

Open in new window

The positioning is just an example, you'd have to find a way to better integrate with the way your div's are defined. The styles themselves can just be added to your existing styles
table.evt {
	font-family: verdana;
	font-size: 8pt;
}
table.evt td {
	text-align: center;
}
table.evt td.nrm { /* normal */
	background-color: silver;
}
table.evt td.out { /* outside curent month */
	background-color: gray;
}
table.evt td.evt { /* event */
	color: blue;
	/* and/or attach 'blue triangle' image here */
}
div#cal {
	float: right;
	border: 1px solid red;
	margin: 5px;
}

Open in new window

I used a session variable to retain the month selected so it will stay the same when a different form is used like your search form. I had to add session_start(); but if you don't want that there may be other ways.
cal-inc.php
0
 

Author Comment

by:TLN_CANADA
ID: 38812615
Thanks so much Robert, it looks fantastic as well! Were you hardcoding it now for testing? Could you tell me what sql  to add to this so that we can add the journal entries in the little calendar and if the user clicks on one it takes them to that particular entry?

Thanks again,

Derek
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38813034
Yes, this line simulates the date that seemed to have an event attached in the picture from your original post:
$cal['20121109'] = 'some event';

Open in new window

To show events from the selected month maybe you can change the start of the include file to something like this:
<?php

$cal = array();

if (isset($_GET['c']) && preg_match('/^\d{6}$/', $_GET['c']) === 1) {
	$day1 = getdate(date_create_from_format('Ymd', $_GET['c'].'01')->getTimestamp());
} elseif (isset($_SESSION['c'])) {
	$day1 = $_SESSION['c'];
} else {
	$day1 = getdate();
	$day1 = getdate(time() - ($day1['mday'] - 1) * 86400); // first of current month
}
$_SESSION['c'] = $day1;

$calyear = $day1['year'];
$calmonth = $day1['mon'];
$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' AND YEAR(entry_timestamp) = $calyear AND MONTH(entry_timestamp) = $calmonth") or die ( mysql_error() );
while ( $row = mysql_fetch_array($query) ) {
	$post_id = $row["entry_id"];
	$date = $row["entry_timestamp"];
	$cal[date('Ymd',strtotime($date))] = $row["entry_title"];
}

Open in new window

This uses the mysql connection that is already open.
0
 

Author Comment

by:TLN_CANADA
ID: 38813048
Thanks Robert, it is saying access denied though for this call to the database.  Should I create a new connection on this page?

Access denied for user 'clear555'@'localhost' (using password: NO) in /home/clear555/public_html/cal-inc.php on line 17

$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' AND YEAR(entry_timestamp) = $calyear AND MONTH(entry_timestamp) = $calmonth") or die ( mysql_error() );

Open in new window


One other quick question about it. I notice the table is appearing with the first 10 days of the next month also on many of the months. Would it be possible to change this? I have attached an image of it on the page. Calendar
0
 

Author Comment

by:TLN_CANADA
ID: 38813051
Sorry, that was the wrong calendar image :) Here it is. Month Image
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38813073
I forgot about the clicking. Try this on line 21 of the code in my previous post:
$cal[date('Ymd',strtotime($date))] = array($row["entry_id"], $row["entry_title"]);

Open in new window

Then further down the include file, use this to show a link:
	for ($d = 0; $d < 42; $d++) {
		if ($d % 7 == 0) {
			echo '</tr>' . PHP_EOL;
			echo '<tr>';
		}
		$a = getdate($cday);
		$cls = ($a['mon'] == $day1['mon']) ? 'nrm' : 'out';
		$t = ""; // title
		$c = $a['mday']; // cell text
		if (isset($cal[date('Ymd', $cday)])) {
			$cls .= ' evt';
			$inf = $cal[date('Ymd', $cday)];
			$post_id = $inf[0];
			$t = ' title="'.$inf[1].'"';
			$c = "<a href = 'editjournal.php?id=$post_id'>$c</a>";
		}
		echo '<td class="'.$cls.'"'.$t.'>'.$c.'</td>';
		$cday += 86400;
	}

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38813094
The connection: you can try but I didn't have to do that, I have a 'conn.php' that I include on the main page and the cal include can use that to query the database just fine. Not sure what's happening there. I think there are different ways of including but not sure why it would be different on your system.

I'm not sure what you mean, just leave out the last row? As you can see the original has this 'problem' as well, often that is done to have the calendar retain a consistent height, but I guess it's not really necessary, you could exit the for loop like this for example:
	for ($d = 0; $d < 42; $d++) {
		if ($d % 7 == 0) {
			echo '</tr>' . PHP_EOL;
			$a = getdate($cday);
			if ($d > 0 && $a['year'].fixzero($a['mon']) > $day1['year'].fixzero($day1['mon']))
				break;
			echo '<tr>';
		} else {
			$a = getdate($cday);
		}

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38813102
for the connection problem you could try (temporarily) moving the code from the include file that's not inside functions to the main page.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38813110
another thought on the connection: did you include the file before or after the connection code?
0
 

Author Comment

by:TLN_CANADA
ID: 38813119
I tried both,

Here is what I have:

      //Including Calendar File
      include 'cal-inc.php';

is this correct?
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38813214
yes, that should normally do the trick, it should be after the connection code, the start of my page is:
<?php
error_reporting(E_ALL);

session_start();

// Database connection
include 'conn.php';

// Calendar functions
include 'cal_inc.php';

?>

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38813336
If nothing obvious is wrong, can you try my previous suggestion:
you could try (temporarily) moving the code from the include file that's not inside functions to the main page
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38813379
Oops, sorry for spamming but I just noticed that in the query I posted (not the one I use for local testing) there is a reference to $username so the 'cal' include must come after that assignment in the main code as well.

How that would cause a permission error is off course the next question, in other words, that's probably not the root of the problem, but needs to be correct anyway.

Also, I see I fell prey to the attachment renaming mechanism. So when I posted my code with cal_inc, I see it will differ from your code as my earlier attachment was renamed to cal-inc. I will change that in my environment to avoid adding confusion.
0
 

Author Comment

by:TLN_CANADA
ID: 38815482
Thanks Robert, I'm working on integrating all that you mentioned above now and will post again soon.
0
 

Author Comment

by:TLN_CANADA
ID: 38815520
I've put all of the PHP in the same file for now and here it what the Calendar PHP part of the page looks like:

$cal = array();

if (isset($_GET['c']) && preg_match('/^\d{6}$/', $_GET['c']) === 1) {
	$day1 = getdate(date_create_from_format('Ymd', $_GET['c'].'01')->getTimestamp());
} elseif (isset($_SESSION['c'])) {
	$day1 = $_SESSION['c'];
} else {
	$day1 = getdate();
	$day1 = getdate(time() - ($day1['mday'] - 1) * 86400); // first of current month
}
$_SESSION['c'] = $day1;

$calyear = $day1['year'];
$calmonth = $day1['mon'];
$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' AND YEAR(entry_timestamp) = $calyear AND MONTH(entry_timestamp) = $calmonth") or die ( mysql_error() );
while ( $row = mysql_fetch_array($query) ) {
	$post_id = $row["entry_id"];
	$date = $row["entry_timestamp"];
	$cal[date('Ymd',strtotime($date))] = array($row["entry_id"], $row["entry_title"]);
}

if (isset($_GET['c']) && preg_match('/^\d{6}$/', $_GET['c']) === 1) {
	$day1 = getdate(date_create_from_format('Ymd', $_GET['c'].'01')->getTimestamp());
} elseif (isset($_SESSION['c'])) {
	$day1 = $_SESSION['c'];
} else {
	$day1 = getdate();
	$day1 = getdate(time() - ($day1['mday'] - 1) * 86400); // first of current month
}
$_SESSION['c'] = $day1;

function showcal() {
	global $cal, $day1;
	echo '<table border=1 class="evt">';
	echo '<tr>';
	echo '<td align="left">';
	echo '<a href="?c='.clink($day1['year'], $day1['mon']-1).'">&lt;</a>';
	echo '</td>';
	echo '<td colspan=5>';
	echo $day1['month'].' '.$day1['year'];
	echo '</td>';
	echo '<td align="right">';
	echo '<a href="?c='.clink($day1['year'], $day1['mon']+1).'">&gt;</a>';
	echo '</td>';
	$cday = $day1[0] - $day1['wday'] * 86400; // start at last sunday // TODO: when month (feb) has only 28 days and starts on sunday, go 7 days back?
		for ($d = 0; $d < 42; $d++) {
		if ($d % 7 == 0) {
			echo '</tr>' . PHP_EOL;
			$a = getdate($cday);
			if ($d > 0 && $a['year'].fixzero($a['mon']) > $day1['year'].fixzero($day1['mon']))
				break;
			echo '<tr>';
		} else {
			$a = getdate($cday);
		$cls = ($a['mon'] == $day1['mon']) ? 'nrm' : 'out';
		$t = ""; // title
		$c = $a['mday']; // cell text
		if (isset($cal[date('Ymd', $cday)])) {
			$cls .= ' evt';
			$inf = $cal[date('Ymd', $cday)];
			$post_id = $inf[0];
			$t = ' title="'.$inf[1].'"';
			$c = "<a href = 'editjournal.php?id=$post_id'>$c</a>";
		}
		echo '<td class="'.$cls.'"'.$t.'>'.$c.'</td>';
		$cday += 86400;
	}
	echo '</tr>' . PHP_EOL;
	echo '</table>';
}

function fixzero($n) {
	return ($n < 10 ? '0' : '').$n;
}

function clink($y, $m) {
	if ($m == 0) {
		$m = 12;
		$y--;
	} elseif ($m == 13) {
		$m = 1;
		$y++;
	}
	return $y.fixzero($m);
}	
	
	
	
	

Open in new window


It gives this error which is the last line of the document:

Parse error: syntax error, unexpected $end in /home/clear555/public_html/searchjournal_old.php on line 384

Thanks so much,

D
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38815551
This is caused by a missing } below line 54. Also there's a whole block ("if (isset($_GET['c']) ...") repeated. The second copy should be removed.
0
 

Author Comment

by:TLN_CANADA
ID: 38815695
Excellent! It's working now!! Thank you so much Robert, this is such a great addition to the page.

I wonder could we make one small change to it that when a user clicks on the particular date on the calendar it reopens the search journal page and shows all the records for that date. Sometimes users will have 2 journal entries for one day so I think it's better to display it this way.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38815776
Good point. It will be mainly deleting a number of things. But the search page needs to be adjusted of course to be able to handle a date, for example with a querystring, although it would also be possible to use a form with a hidden field. Can you handle that part?

The include file will need a number of changes. The query can just select distinct dates, the array elements could just be assigned 'true' for example as you don't need any info to show the links anymore. The part with $inf will then have to be adjusted to link to the search url. If you want me to handle that please post your current version.
0
 

Author Comment

by:TLN_CANADA
ID: 38815904
Thank you very much, yes that would be much appreciated as I do not know how to do this.

Here is the entire current page I have:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php

	//Including Calendar File
//include 'cal-inc_testing.php';


	

error_reporting(0);
	/**
	* Key to include phpFox
	*
	*/
	define('PHPFOX', true);

	/**
	* Directory Seperator
	*
	*/
	define('PHPFOX_DS', DIRECTORY_SEPARATOR);

	/**
	* phpFox Root Directory
	*
	*/
	define('PHPFOX_DIR', dirname(__FILE__) . PHPFOX_DS);

	define('PHPFOX_START_TIME', array_sum(explode(' ', microtime())));

	// Require phpFox Init
	require(PHPFOX_DIR . 'include' . PHPFOX_DS . 'init.inc.php');
	
	// Connecting to the DB
	mysql_connect('localhost','foxdbmain','xxx!') or die ( mysql_error() );
	mysql_select_db("foxdbmain") or die ( mysql_error() );

	$username = Phpfox::getUserBy('full_name');
	
	

	
	$pic_abs = Phpfox::getUserBy('user_image');
	$pic_abs = str_replace("%s","",$pic_abs);
	
	if ( $pic_abs == NULL )
	{
		$URL = "http://www.clearthemirror.com/theme/frontend/default/style/default/image/noimage/profile_50.png";
	}
	else
	{
		$URL = "http://www.clearthemirror.com/file/pic/user/" . "$pic_abs";
	}
	
// Beginning of Calendar code

$cal = array();

if (isset($_GET['c']) && preg_match('/^\d{6}$/', $_GET['c']) === 1) {
	$day1 = getdate(date_create_from_format('Ymd', $_GET['c'].'01')->getTimestamp());
} elseif (isset($_SESSION['c'])) {
	$day1 = $_SESSION['c'];
} else {
	$day1 = getdate();
	$day1 = getdate(time() - ($day1['mday'] - 1) * 86400); // first of current month
}
$_SESSION['c'] = $day1;

$calyear = $day1['year'];
$calmonth = $day1['mon'];
$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' AND YEAR(entry_timestamp) = $calyear AND MONTH(entry_timestamp) = $calmonth") or die ( mysql_error() );
while ( $row = mysql_fetch_array($query) ) {
	$post_id = $row["entry_id"];
	$date = $row["entry_timestamp"];
	$cal[date('Ymd',strtotime($date))] = array($row["entry_id"], $row["entry_title"]);
}

function showcal() {
	global $cal, $day1;
	echo '<table border=1 class="evt">';
	echo '<tr>';
	echo '<td align="left">';
	echo '<a href="?c='.clink($day1['year'], $day1['mon']-1).'">&lt;</a>';
	echo '</td>';
	echo '<td colspan=5>';
	echo $day1['month'].' '.$day1['year'];
	echo '</td>';
	echo '<td align="right">';
	echo '<a href="?c='.clink($day1['year'], $day1['mon']+1).'">&gt;</a>';
	echo '</td>';
	$cday = $day1[0] - $day1['wday'] * 86400; // start at last sunday // TODO: when month (feb) has only 28 days and starts on sunday, go 7 days back?
		for ($d = 0; $d < 42; $d++) {
		if ($d % 7 == 0) {
			echo '</tr>' . PHP_EOL;
			$a = getdate($cday);
			if ($d > 0 && $a['year'].fixzero($a['mon']) > $day1['year'].fixzero($day1['mon']))
				break;
			echo '<tr>';
		} else {
			$a = getdate($cday);
			    }
		$cls = ($a['mon'] == $day1['mon']) ? 'nrm' : 'out';
		$t = ""; // title
		$c = $a['mday']; // cell text
		if (isset($cal[date('Ymd', $cday)])) {
			$cls .= ' evt';
			$inf = $cal[date('Ymd', $cday)];
			$post_id = $inf[0];
			$t = ' title="'.$inf[1].'"';
			$c = "<a href = 'editjournal.php?id=$post_id'>$c</a>";
		}
		echo '<td class="'.$cls.'"'.$t.'>'.$c.'</td>';
		$cday += 86400;
	}
	echo '</tr>' . PHP_EOL;
	echo '</table>';
}

function fixzero($n) {
	return ($n < 10 ? '0' : '').$n;
}

function clink($y, $m) {
	if ($m == 0) {
		$m = 12;
		$y--;
	} elseif ($m == 13) {
		$m = 1;
		$y++;
	}
	return $y.fixzero($m);
}	
	
	
	
	
?>
<style type = "text/css">

/* Styles for Calendar */ 

table.evt {
	font-family: verdana;
	font-size: 8pt;
}
table.evt td {
	text-align: center;
}
table.evt td.nrm { /* normal */
	background-color: silver;
}
table.evt td.out { /* outside curent month */
	background-color: gray;
}
table.evt td.evt { /* event */
	color: blue;
	/* and/or attach 'blue triangle' image here */
}
div#cal {
	float: right;
	border: 1px solid red;
	margin: 5px;
}

/* Styles for Calendar */ 

html,body{
	width:100%;
	height:100%;
	margin:0px;
	padding:0px;
}
div {
	margin: 0;
	padding: 0;
}
body {
	background-color: white;
}
div#HeaderTitle {
	float: left;
	width: 50%;
	text-align: left;
	height: 24px;
}
div#HeaderButton {
	float: right;
	width: 50%;
	text-align: right;
	height: 24px;
}
.ClearFloat {
	clear: both;
}
.Seperator {
	margin-top: 5px;
	margin-bottom: 5px;
}
#BarSearch {
	float: left;
	width: 50%;
	text-align: left;
	height: 24px;
}
#BarAction {
	float: right;
	width: 50%;
	text-align: right;
	height: 24px;
}
#Side {
	float: left;
	position: relative;
	width: 10%;
	height: 100%;
	text-align: center;
	margin-left: 5px;
}
#Journal {
	float: right;
	position: relative;
	width: 88%;
	height: 100%;
}
#Journal p {
	margin-top: 0px;
}
#Journal_Title {
	font-weight: bold;
}
#Entry_Date {
	text-align: center;
}
#Entry_Month {
    border: 1px solid black;
    border-radius: 10px 10px 10px 10px;
    font-size: 14px;
    height: 25px;
    line-height: 25px;
    background: -moz-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	background: -webkit-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
    font-weight: bold;	
}
#Entry_Day {
	background: -moz-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	background: -webkit-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	font-size: 35px;
	font-weight: bold;
}
</style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<div id = "Wrapper">
	<div id = "Header">
		<div id = "HeaderTitle">Search Journals:</div>
		<div id = "HeaderButton"><input type = "button" value = "New Journal" target="_blank" onClick = "location.href = 'http://www.clearthemirror.com/index.php?do=/clearthemirror/newjournal/'"/></div>
		<div class = "ClearFloat"></div>
	</div>
		<div class = "Seperator"><hr></div>
	<div id = "Bar">
		<div id = "BarSearch">
			<form method = "POST"><input type = "text" name = "search_journal" value = "Search Journals ..." onClick = "this.value = '';"/><input type = "submit" value = "GO"/></form>
		</div>
		<div id = "BarAction"><form method = "POST">Show The Last <select name = "FilterRow"><option value = "5">5</option><option value = "10">10</option><option value = "20">20</option><option value = "all">All</option></select><input type = "submit" value = "GO"/> Items</form></div>
		<div class = "ClearFloat"></div>
	</div>
		<div class = "Seperator"><hr></div>

		<?php
			if ( ! isset($_POST["search_journal"]) )
			{
								$select_all = false;
								
								if ( ! isset($_POST["FilterRow"]) )
								{
									$limit = 5; // default
								}
								else if ( $_POST["FilterRow"] == "all" )
								{
									$select_all = true;
								}
								else
								{
									$limit = (int)$_POST["FilterRow"];
								}
								
								if ( $select_all )
								{
									$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' ORDER BY entry_id DESC") or die ( mysql_error() );
								}
								else
								{
									$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' ORDER BY entry_id DESC LIMIT $limit") or die ( mysql_error() );
								}
								
								$total_things = mysql_num_rows($query);
								
								if ( $total_things == 0 )
								{
									echo "You do not seem to have posted any journal! Why don't you start? :) ";
								}
								else
							{
								while ( $row = mysql_fetch_array($query) )
								{
								$post_id = $row["entry_id"];
								$date = $row["entry_timestamp"];
								$day = date('d',strtotime($date));
								$month = date('F',strtotime($date));
								?>
						<div id = "Content">
										<div id = "Side">
												<div id = "Entry_Month"><?php echo $month; ?></div>
												<div id = "Entry_Day"><?php echo $day; ?></div>									
											<img height = "70px" width = "50px" src = "<?php echo $URL; ?>">
										</div>
										<div id = "Journal">
											<p id = "Journal_Title"><?php echo $row["entry_title"]; ?></p>
											<p id = "Journal_Sender"><?php echo "By: " . $username; ?></p>
											<p id = "Journal_Content"><?php echo $row["entry_text"];?></p>
											<div class = "Seperator"><hr></div>
											<p id = "Journal_Timestamp"><?php echo $date . " - <a href = 'editjournal.php?id=$post_id'>Edit</a> - <a href = 'deletejournal.php?id=$post_id'>Delete</a>";?></p>
										</div>
						<div class = "ClearFloat"></div>
						<div class = "Seperator"><hr></div>
						</div>
								<?php
								}
							}			
			}
			else
			{
								$term = $_POST["search_journal"];
			
								$query = mysql_query("SELECT * FROM journal_table WHERE entry_text LIKE '%$term%' OR entry_title LIKE '%$term%' ORDER BY entry_id DESC") or die ( mysql_error() );
								
								$total_things = mysql_num_rows($query);
								
								if ( $total_things == 0 )
								{
									echo "No Result For The Term Selected.<br><br>";
								}
								else
							{
								while ( $row = mysql_fetch_array($query) )
								{
								$post_id = $row["entry_id"];
								?>
						<div id = "Content">
										<div id = "Journal" style = "width: 100%;">
											<p id = "Journal_Title"><?php echo $row["entry_title"]; ?></p>
											<p id = "Journal_Sender"><?php echo "By: " . $row["user_id"]; ?></p>
											<p id = "Journal_Content"><?php echo $row["entry_text"];?></p>
											<div class = "Seperator"><hr></div>
											<p id = "Journal_Timestamp"><?php echo $row["entry_timestamp"] . " - <a href = 'editjournal.php?id=$post_id'>Edit</a> - <a href = 'deletejournal.php?id=$post_id'>Delete</a>";?></p>
										</div>
						<div class = "ClearFloat"></div>
						<div class = "Seperator"><hr></div>
						</div>
								<?php
								unset($_POST["search_journal"]);
								}
							}				
			}
			

		?>
</div> <!-- end of Wrapper -->
<div id="cal"><? showcal() ?></div>
</body>
</html>

Open in new window

0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 38816234
Try this please:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php

	//Including Calendar File
//include 'cal-inc_testing.php';

error_reporting(0);
	/**
	* Key to include phpFox
	*
	*/
	define('PHPFOX', true);

	/**
	* Directory Seperator
	*
	*/
	define('PHPFOX_DS', DIRECTORY_SEPARATOR);

	/**
	* phpFox Root Directory
	*
	*/
	define('PHPFOX_DIR', dirname(__FILE__) . PHPFOX_DS);

	define('PHPFOX_START_TIME', array_sum(explode(' ', microtime())));

	// Require phpFox Init
	require(PHPFOX_DIR . 'include' . PHPFOX_DS . 'init.inc.php');
	
	// Connecting to the DB
	mysql_connect('localhost','foxdbmain','xxx!') or die ( mysql_error() );
	mysql_select_db("foxdbmain") or die ( mysql_error() );

	$username = Phpfox::getUserBy('full_name');
	
	

	
	$pic_abs = Phpfox::getUserBy('user_image');
	$pic_abs = str_replace("%s","",$pic_abs);
	
	if ( $pic_abs == NULL )
	{
		$URL = "http://www.clearthemirror.com/theme/frontend/default/style/default/image/noimage/profile_50.png";
	}
	else
	{
		$URL = "http://www.clearthemirror.com/file/pic/user/" . "$pic_abs";
	}

// Beginning of Calendar code

$cal = array();

if (isset($_GET['c']) && preg_match('/^\d{6}$/', $_GET['c']) === 1) {
	$day1 = getdate(date_create_from_format('Ymd', $_GET['c'].'01')->getTimestamp());
} elseif (isset($_SESSION['c'])) {
	$day1 = $_SESSION['c'];
} else {
	$day1 = getdate();
	$day1 = getdate(time() - ($day1['mday'] - 1) * 86400); // first of current month
}
$_SESSION['c'] = $day1;

$calyear = $day1['year'];
$calmonth = $day1['mon'];
$query = mysql_query("SELECT DISTINCT DAY(entry_timestamp) AS D FROM journal_table WHERE user_id = '$username' AND YEAR(entry_timestamp) = $calyear AND MONTH(entry_timestamp) = $calmonth") or die ( mysql_error() );
while ( $row = mysql_fetch_array($query) ) {
	$cal[$row["D"]] = true;
}

function showcal() {
	global $cal, $day1;
	echo '<table border=1 class="evt">';
	echo '<tr>';
	echo '<td align="left">';
	echo '<a href="?c='.clink($day1['year'], $day1['mon']-1).'">&lt;</a>';
	echo '</td>';
	echo '<td colspan=5>';
	echo $day1['month'].' '.$day1['year'];
	echo '</td>';
	echo '<td align="right">';
	echo '<a href="?c='.clink($day1['year'], $day1['mon']+1).'">&gt;</a>';
	echo '</td>';
	echo '</tr>' . PHP_EOL;
	echo '<tr>';
	echo '<th>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th>';
	$cday = $day1[0] - $day1['wday'] * 86400; // start at last sunday
	for ($d = 0; $d < 42; $d++) {
		if ($d % 7 == 0) {
			echo '</tr>' . PHP_EOL;
			$a = getdate($cday);
			if ($d > 0 && $a['year'].fixzero($a['mon']) > $day1['year'].fixzero($day1['mon']))
				break;
			echo '<tr>';
		} else {
			$a = getdate($cday);
		}
		$cls = ($a['mon'] == $day1['mon']) ? 'nrm' : 'out';
		$t = ""; // title
		$c = $a['mday']; // cell text
		if ($a['mon'] == $day1['mon'] && isset($cal[$c])) {
			$cls .= ' evt';
			$t = ' title="show '.date('Y-m-d', $cday).'"';
			$c = "<a href = '?dt=".date('Ymd', $cday)."'>$c</a>";
		}
		echo '<td class="'.$cls.'"'.$t.'>'.$c.'</td>';
		$cday += 86400;
	}
	echo '</tr>' . PHP_EOL;
	echo '</table>';
}

function fixzero($n) {
	return ($n < 10 ? '0' : '').$n;
}

function clink($y, $m) {
	if ($m == 0) {
		$m = 12;
		$y--;
	} elseif ($m == 13) {
		$m = 1;
		$y++;
	}
	return $y.fixzero($m);
}	
	
	
	
	
?>
<style type = "text/css">

/* Styles for Calendar */ 

table.evt {
	font-family: verdana;
	font-size: 8pt;
}
table.evt td {
	text-align: center;
}
table.evt td.nrm { /* normal */
	background-color: silver;
}
table.evt td.out { /* outside curent month */
	background-color: gray;
}
table.evt td.evt { /* event */
	color: blue;
	/* and/or attach 'blue triangle' image here */
}
div#cal {
	float: right;
	border: 1px solid red;
	margin: 5px;
}

/* Styles for Calendar */ 

html,body{
	width:100%;
	height:100%;
	margin:0px;
	padding:0px;
}
div {
	margin: 0;
	padding: 0;
}
body {
	background-color: white;
}
div#HeaderTitle {
	float: left;
	width: 50%;
	text-align: left;
	height: 24px;
}
div#HeaderButton {
	float: right;
	width: 50%;
	text-align: right;
	height: 24px;
}
.ClearFloat {
	clear: both;
}
.Seperator {
	margin-top: 5px;
	margin-bottom: 5px;
}
#BarSearch {
	float: left;
	width: 50%;
	text-align: left;
	height: 24px;
}
#BarAction {
	float: right;
	width: 50%;
	text-align: right;
	height: 24px;
}
#Side {
	float: left;
	position: relative;
	width: 10%;
	height: 100%;
	text-align: center;
	margin-left: 5px;
}
#Journal {
	float: right;
	position: relative;
	width: 88%;
	height: 100%;
}
#Journal p {
	margin-top: 0px;
}
#Journal_Title {
	font-weight: bold;
}
#Entry_Date {
	text-align: center;
}
#Entry_Month {
    border: 1px solid black;
    border-radius: 10px 10px 10px 10px;
    font-size: 14px;
    height: 25px;
    line-height: 25px;
    background: -moz-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	background: -webkit-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
    font-weight: bold;	
}
#Entry_Day {
	background: -moz-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	background: -webkit-linear-gradient(white, gray, white) repeat scroll 0% 0% transparent;
	font-size: 35px;
	font-weight: bold;
}
</style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<div id = "Wrapper">
	<div id = "Header">
		<div id = "HeaderTitle">Search Journals:</div>
		<div id = "HeaderButton"><input type = "button" value = "New Journal" target="_blank" onClick = "location.href = 'http://www.clearthemirror.com/index.php?do=/clearthemirror/newjournal/'"/></div>
		<div class = "ClearFloat"></div>
	</div>
		<div class = "Seperator"><hr></div>
	<div id = "Bar">
		<div id = "BarSearch">
			<form method = "POST"><input type = "text" name = "search_journal" value = "Search Journals ..." onClick = "this.value = '';"/><input type = "submit" value = "GO"/></form>
		</div>
		<div id = "BarAction"><form method = "POST">Show The Last <select name = "FilterRow"><option value = "5">5</option><option value = "10">10</option><option value = "20">20</option><option value = "all">All</option></select><input type = "submit" value = "GO"/> Items</form></div>
		<div class = "ClearFloat"></div>
	</div>
		<div class = "Seperator"><hr></div>

		<?php
			if ( ! isset($_POST["search_journal"]) )
			{
				if ( isset($_GET["dt"]) ) // show 1 day, selected from calendar
				{
					$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' AND DATE_FORMAT(entry_timestamp, '%Y%m%d') = '{$_GET["dt"]}' ORDER BY entry_id DESC") or die ( mysql_error() );
				}
				else
				{
								$select_all = false;
								
								if ( ! isset($_POST["FilterRow"]) )
								{
									$limit = 5; // default
								}
								else if ( $_POST["FilterRow"] == "all" )
								{
									$select_all = true;
								}
								else
								{
									$limit = (int)$_POST["FilterRow"];
								}
								
								if ( $select_all )
								{
									$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' ORDER BY entry_id DESC") or die ( mysql_error() );
								}
								else
								{
									$query = mysql_query("SELECT * FROM journal_table WHERE user_id = '$username' ORDER BY entry_id DESC LIMIT $limit") or die ( mysql_error() );
								}
				}

								$total_things = mysql_num_rows($query);
								
								if ( $total_things == 0 )
								{
									echo "You do not seem to have posted any journal! Why don't you start? :) ";
								}
								else
							{
								while ( $row = mysql_fetch_array($query) )
								{
								$post_id = $row["entry_id"];
								$date = $row["entry_timestamp"];
								$day = date('d',strtotime($date));
								$month = date('F',strtotime($date));
								?>
						<div id = "Content">
										<div id = "Side">
												<div id = "Entry_Month"><?php echo $month; ?></div>
												<div id = "Entry_Day"><?php echo $day; ?></div>									
											<img height = "70px" width = "50px" src = "<?php echo $URL; ?>">
										</div>
										<div id = "Journal">
											<p id = "Journal_Title"><?php echo $row["entry_title"]; ?></p>
											<p id = "Journal_Sender"><?php echo "By: " . $username; ?></p>
											<p id = "Journal_Content"><?php echo $row["entry_text"];?></p>
											<div class = "Seperator"><hr></div>
											<p id = "Journal_Timestamp"><?php echo $date . " - <a href = 'editjournal.php?id=$post_id'>Edit</a> - <a href = 'deletejournal.php?id=$post_id'>Delete</a>";?></p>
										</div>
						<div class = "ClearFloat"></div>
						<div class = "Seperator"><hr></div>
						</div>
								<?php
								}
							}			
			}
			else
			{
								$term = $_POST["search_journal"];
			
								$query = mysql_query("SELECT * FROM journal_table WHERE entry_text LIKE '%$term%' OR entry_title LIKE '%$term%' ORDER BY entry_id DESC") or die ( mysql_error() );
								
								$total_things = mysql_num_rows($query);
								
								if ( $total_things == 0 )
								{
									echo "No Result For The Term Selected.<br><br>";
								}
								else
							{
								while ( $row = mysql_fetch_array($query) )
								{
								$post_id = $row["entry_id"];
								?>
						<div id = "Content">
										<div id = "Journal" style = "width: 100%;">
											<p id = "Journal_Title"><?php echo $row["entry_title"]; ?></p>
											<p id = "Journal_Sender"><?php echo "By: " . $row["user_id"]; ?></p>
											<p id = "Journal_Content"><?php echo $row["entry_text"];?></p>
											<div class = "Seperator"><hr></div>
											<p id = "Journal_Timestamp"><?php echo $row["entry_timestamp"] . " - <a href = 'editjournal.php?id=$post_id'>Edit</a> - <a href = 'deletejournal.php?id=$post_id'>Delete</a>";?></p>
										</div>
						<div class = "ClearFloat"></div>
						<div class = "Seperator"><hr></div>
						</div>
								<?php
								unset($_POST["search_journal"]);
								}
							}				
			}
			

		?>
</div> <!-- end of Wrapper -->
<div id="cal"><? showcal() ?></div>
</body>
</html>

Open in new window

0
 

Author Comment

by:TLN_CANADA
ID: 38816292
Perfect Robert! Works like a charm!

You had mentioned the possibility of using ajax to open the next month in the calendar without refreshing the page. Would you like me to open a new question about this?

Thanks again for your great help,

D
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38816348
Great!

Yes, that would be better; I think I can come up with a basic solution, but there are much greater experts in that topic area. And I have a slight suspicion that the problem we had with the connection will come up again, so make sure you mention the phpfox code or just refer to this question. The page you will be calling will probably not return a full html page but it will have to work on its own, including the connection.
0
 

Author Comment

by:TLN_CANADA
ID: 38816368
Thank you Robert, yes I will do this. You're help with this was much appreciated!

I have another question open that I'm struggling with and need to get it working asap.

If you had a couple of minutes to take a look at it that would be great as I think the other expert won't be online until later tonight. No worries at all if you don't have time :)

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28006761.html
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38816468
Sure, I had a quick look but I don't wanna steal his points ;-)

Looks to me like you forgot to copy the id in the <select> tag.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38816509
Also, in the popup you switched the order of the form and the script, the order needs to be the way it was.
0
 

Author Comment

by:TLN_CANADA
ID: 38816580
If you are more comfortable with it, I can give him the points for this question (as he provided a sample solution) and then open a new question which I could direct you to?

I wouldn't ask only I need to get this solved this afternoon and I think he won't be online until later tonight.

I tried this solution but it is still not passing the variable :(
0
 

Author Comment

by:TLN_CANADA
ID: 38816586
Here is the parent page as it currently is :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function LaunchPopup(page,width,height) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no, scrollbars=yes,resizable=yes, dependent=no,directories=no, width=" + width + ",height=" + height + ",x=50,y=50");
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post"  action="">
<input type="text" id="parentValue" value="22" />
<p><a href="javascript:LaunchPopup('mednow2_beforescriptpass.htm','400','200');">Open Popup</a></p>
  <label>Dyad
  <select name="select" id= "selectlist" >
    <option value="1">Start a Dyad Now</option>
    <option value="2">Change Dyad Question</option>
  </select>
  </label>

Open in new window


and the child page is as it was before.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38816616
the parent page looks ok, the popup seems to miss a "var":
<form id="form2" name="form2" method="post" action="">
	<input type = "text" id = "Minutes" value = "5" readonly="readonly">
</form>

<script>

if (opener.document){

	var parent = opener.document;

	var e = parent .getElementById("selectlist");

	var minvalue = e.options[e.selectedIndex].value;

	document.form2.Minutes.value = minvalue ;

}
</script>

Open in new window

0
 

Author Comment

by:TLN_CANADA
ID: 38816661
Thanks, this still isn;t displaying though. I've tried the javascript on the child page both before and after. Here is what I have now:

Parent Page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function LaunchPopup(page,width,height) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no, scrollbars=yes,resizable=yes, dependent=no,directories=no, width=" + width + ",height=" + height + ",x=50,y=50");
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post"  action="">
<input type="text" id="parentValue" value="22" />
<p><a href="javascript:LaunchPopup('mednow2_beforescriptpass.htm','400','200');">Open Popup</a></p>
  <label>Dyad
  <select name="select" id= "selectlist" >
    <option value="1">Start a Dyad Now</option>
    <option value="2">Change Dyad Question</option>
  </select>
  </label>

Open in new window


Child Page:

<form id="form2" name="form2" method="post" action="">
	<input type = "button" value = "STOP" class = "button" style="margin-left:160px;margin-top:150px;" onClick = "StopTimer();">
	<input type = "button" value = "PAUSE/CONTINUE" class = "button" onClick = "PauseTimer();">
	<input type = "button" value = "RESET" class = "button" onClick = "location.reload();">
</div>
<div id = "Info">
	<input type = "text" id = "Minutes" value = "40" readonly="readonly">
	
	<script>

if (opener.document){

	var parent = opener.document;

	var e = parent .getElementById("selectlist");

	var minvalue = e.options[e.selectedIndex].value;

	document.form2.Minutes.value = minvalue ;

}
</script>
	</form>

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38816701
A little friendly advice: get it to work first, then start adding things. That way you will be able to recognize which addition causes a problem.

Apart from that you're still not following the posted code: open form tag, form content , close form tag, open script tag, script content, close script tag. There are other (imho better) ways to do this, but the way this is built now, that's the way it needs to be and not one inside the other or in a different order.

That's it for me for today, time for bed in Holland...
0
 

Author Comment

by:TLN_CANADA
ID: 38816705
No problem Robert, thank you very much for your assistance with this.
0
 

Author Comment

by:TLN_CANADA
ID: 38816706
Goodnight :)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now