Hi,
I'm hoping someone here can help me.
I have a database that has several entries per user. What I want to do is to:
1) Create a dropdown menu whose options consist of each journal entry date for that particular user, and
2) Once one of the dates is selected from the dropdown menu, I'd like to display the entry associated with that particular date.
I've managed to create the dropdown menu (code for retrieve.php pasted below):
<?php
require_once ('../includes/config.inc');
$page_title = 'View Your Journal Entries';
include ('../includes/header2.html');
?>
<script language="JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<div id="mainarea">
<table width="700" height="400" border="1" bordercolor="#999999" bgcolor="#FFFFFF" cellpadding="10">
<tr><td valign="top"><h1>Your Journal Entries</h1>
<form action = "retrieve2.php" Method = "POST">
<select name="selObj" onChange="MM_jumpMenu('parent',selObj,0)">
<option selected>Select an Entry</option>
<?php
if (!isset($_SESSION['user_id'])) {
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "../index.php");
ob_end_clean();
exit();
} else {
$uid = ($_SESSION['user_id']);
$fn = ($_SESSION['first_name']);
}
require_once ('../../../files/mysql_connect.php');
$query = mysql_query("SELECT * FROM entries WHERE user_id='$uid' ORDER BY 'journal_DATE' DESC");
while($row = mysql_fetch_array($query)) {
//notice the change in the url bellow
print '<option value="retrieve2.php?action=journal_DATE='.$row["journal_DATE"].'">'.$row["journal_DATE"];
print '</option>';
}
mysql_close();
?>
</td></tr>
<tr><td class="style1" valign="top"><a href="create.php">Create another entry</a>
</td></tr></table>
<?php
include ('../includes/footer2.html');
?>
What I can't figure out is how to achieve goal #2.
I know there's problems with the code (retrieve2.php) below, but can anyone tell me how to fix it? Thanks so much!
<?php
require_once ('../includes/config.inc');
$page_title = 'View Your Journal Entries';
include ('../includes/header2.html');
?>
<?php
if (!isset($_SESSION['user_id'])) {
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "../../index.php");
ob_end_clean();
exit();
} else {
$uid = ($_SESSION['user_id']);
$fn = ($_SESSION['first_name']);
}
if (isset($_POST['selObj'])) {
require_once ('../../../files/mysql_connect.php');
$query = "SELECT journal_entry FROM entries WHERE user_id='$uid' AND journal_DATE={$_POST['selObj']}";
$result = mysql_query ($query);
while($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "{$row['journal_entry']}";
}}
?>