how to retrieve the records according to the selected option and specific dates(javascript) from PHPMyAdmin and display them to the next page by using php.
sorry if the coding is a little bit messy. When i have been assigned to this project on the end of december last year, i started learning php and javascript which i know nothing before. I can explore or try-and-error to find the correct coding, but the time is running out and i must finish it on the next month. I really appreciate if you have a better suggestion. thank you.
<?php
session_start();
if(session_is_registered("USERNAME"))
{
echo"<strong>Welcome,</strong>"; echo $_SESSION['USERNAME'];
}
else
{
print "<p> You are not logged-in!</p>";
exit;}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
//Sortable table script- Han Yu
[email protected]
//Script featured on
http://www.javascriptkit.com
var domok=document.all||document.getElementById||docum ent.getElementByNama
if (domok)
document.write('<SCRIPT SRC="Scripts/sortTable.
js"><\/SCRIPT>')
</script>
</head>
<body onLoad='if (domok) initTable("table0")'>
<table width="763" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="154" height="57" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="105" height="44" valign="top"><p align="center"><strong><a href="file:///C|/Documents%20and%20Settings/Administrator/My%20Documents/Unnamed%20Site%2025/logout.php">[Sign-Out]</a></strong>
</p>
<p> </p></td>
</tr>
</table></td>
<td width="146"> </td>
<td width="6"> </td>
<td width="31"> </td>
<td width="167"> </td>
<td width="220"> </td>
<td width="36"> </td>
<td width="1"> </td>
<td width="2"> </td>
</tr>
<tr>
<td height="57" colspan="6" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="839" height="57" valign="top"><div align="Center"> <strong>
Aduan MaklumBalas</strong></div></td>
</tr>
</table></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" rowspan="5" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="204" height="56" valign="top"> <script type=text/javascript>
function Caption1() {
// JAVASCRIPT INCLUDE FILE - (c) J R Stockton >= 2004-08-13
//
http://www.merlyn.demon.co.uk/include1.js
// Routines may be copied, but URL must not be linked to.
}
// General Utilities :
function LS(x) { return String(x).replace(/\b(\d)\b/g, '0$1') }
function LZ(x) { return (x<0||x>=10?"":"0") + x }
function LZZ(x) { return x<0||x>=100?""+x:"0"+LZ(x) }
function lz(s) { var t = String(s)
return t.length==1 ? "0"+t : t } // slower?
function ShowFF() { // Args are functions, last Arg is box height
var Len = --arguments.length, S = ""
for (var j=0 ; j<Len ; j++) {
if (j>0) S += "\n\n"
S += arguments[j].toString() } // ??? but replace < > & ???
// Depict(BoxX, arguments[Len], S, "lightgreen") ;
return "" }
function ShowDo(Fn, Ht) { // N.B. this calls Fn()
//Depict(BoxX, Ht, Fn.toString(), "red" ) ;
Fn() ; return "" }
// Library :
function GlobalNames() {
Mon3 = ["Jan", "Feb", "Mac", "Apr", "Mei", "Jun",
"Jul", "Ogs", "Sep", "Okt", "Nov", "Dis"]
Day3 = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'] }
function Lz(x) { return (x<0||x>=10?"":"0") + x /* local */ }
function LengthOfMonth(Y, M) { // M=1..12 // OK in NS4? Mac?
with (new Date(Y,M,1,12)) { setDate(0) ; return getDate() } }
ShowDo(GlobalNames, 4)
ShowFF(Lz, LengthOfMonth, 4)
function Department() {
var S = document.frm.bahaGian.length;
var X = document.frm.bahaGian.selectedIndex;
var Y = document.frm.bahaGian.options[X].text;
for (var i = 0; i < S; i++) {
thisitem = document.frm.bahaGian.options[i].text;
if ( thisitem == Y ) {
return thisitem; }
}
//this function will return the selected option of bahaGian
}
</script>
<strong>
<script>
function initTable(obj)
{
// Check whether it's viewed by IE 5.0 or greater
if (! checkBrowser()) return;
// Local variables
var countCol;
var nChildNodes;
var innerMostNode;
var nColSpan, nRowSpannedTitleCol, colPos;
var cell, cellText;
var titleFound = false;
var rNRowSpan, rNColSpan;
// Initializing global table object variable
if (obj.tagName == "TABLE")
{
// Assumes that the obj is THE OBJECT
table = obj;
}
else
{
// Assumes that the obj is the id of the object
table = document.getElementById(obj);
}
// Check whether it's an object
if (table == null) return;
// Check whether it's a table
if (table.tagName != "TABLE") return;
// Initializing the max col number with the size of last data row
maxNCol = table.rows[table.rows.length-1].cells.length;
// Initializing arrays
rowArray = new Array();
colSpanArray = new Array();
colTitleFilled = new Array();
titleRowArray = new Array();
titleRowCellArray = new Array();
for (var i=0; i<maxNCol; i++)
colTitleFilled[i] = false;
// Setting the number of rows
nRow = table.rows.length;
// Should have at least 1 row
if (nRow < 1) return;
// Initialization of local variables
actualNRow = 0; // Number of actual data rows
rNRowSpan = 0; // Remaining rows in the row span
rNColSpan = 0; // Remaining cols in the col span
nRowSpannedTitleCol = 0; // Number of title cols from row span
// Loop through rows
for (var i=0; i<nRow; i++)
{
nColSpan = 1, colPos = 0;
// Loop through columns
// Initializing
for (var j=0; j<table.rows[i].cells.length; j++)
{
// Do this iff title has not been found
if (titleFound == false)
{
if (table.rows[i].cells[j].rowSpan > 1)
{
if (table.rows[i].cells[j].colSpan < 2)
{
titleSpanCellArray[colPos] =
table.rows[i].cells[j];
colTitleFilled[colPos] = true;
nRowSpannedTitleCol++;
}
if (table.rows[i].cells[j].rowSpan - 1
> rNRowSpan)
{
rNRowSpan =
table.
rows[i].cells[j].
rowSpan - 1;
if (table.rows[i].
cells[j].colSpan > 1)
rNColSpan =
rNRowSpan + 1;
}
}
}
if (table.rows[i].cells[j].colSpan > 1 &&
rNColSpan == 0)
{
nColSpan = table.rows[i].cells[j].colSpan;
colPos += nColSpan;
}
else
{
colPos++;
}
}
// Setting up the title cells
if (titleFound == false && nColSpan == 1 &&
rNRowSpan == 0 && rNColSpan == 0 && titleFound == false)
{
colSpanArray[i] = true;
titleFound = true;
// Using indivisual cell as an array element
countCol = 0;
for (var j=0;
j<table.rows[i].cells.length
+ nRowSpannedTitleCol; j++)
{
if (colTitleFilled[j] != true)
{
titleRowCellArray[j] =
table.rows[i].cells[countCol];
countCol++;
}
else
{
titleRowCellArray[j] =
titleSpanCellArray[j];
}
}
}
// Setting up the data rows
else if (titleFound == true && nColSpan == 1 && rNRowSpan == 0)
{
for (var j=0; j<table.rows[i].cells.length; j++)
{
// Can't have row span in record rows ...
if (table.rows[i].cells[j].rowSpan > 1) return;
nChildNodes =
table.rows[i].
cells[j].firstChild.childNodes.
length;
innerMostNode =
table.rows[i].
cells[j].firstChild;
while ( nChildNodes != 0)
{
innerMostNode =
innerMostNode.
firstChild;
nChildNodes =
innerMostNode.
childNodes.
length;
}
if (j == 0)
{
rowArray[actualNRow] =
innerMostNode.data;
}
else
{
rowArray[actualNRow] += recDelimiter +
innerMostNode.data;
}
}
// Inconsistent col lengh for data rows
if (table.rows[i].cells.length > maxNCol)
return;
actualNRow++;
colSpanArray[i] = false;
}
else if (nColSpan == 1 && rNRowSpan == 0 &&
rNColSpan == 0 && titleFound == false)
{
colSpanArray[i] = false;
}
else
{
colSpanArray[i] = true;
}
// Counters for row/column spans
if (rNRowSpan > 0) rNRowSpan--;
if (rNColSpan > 0) rNColSpan--;
}
// If the row number is < 1, no need to do anything ...
if (actualNRow < 1) return;
// Re-drawing the title row
for (var j=0; j<maxNCol; j++)
{
// If for some reason, the rows do NOT have any child, then
// simply return ...
if (titleRowCellArray[j].childNodes.length == 0) return;
if (titleRowCellArray[j].firstChild != null)
{
nChildNodes =
titleRowCellArray[j].
firstChild.childNodes.length;
innerMostNode =
titleRowCellArray[j].firstChild;
while ( nChildNodes != 0)
{
innerMostNode =
innerMostNode.firstChild;
nChildNodes =
innerMostNode.
childNodes.
length;
}
cellText = innerMostNode.data;
}
else
{
cellText = "column(" + j + ")";
}
titleRowArray[j] = cellText;
titleRowCellArray[j].innerHTML =
'<a ' +
linkEventString +
j + ',' + '"' + table.id + '"' + ');\'>' +
'<' + titleFace + '>' + cellText +
'</' + titleFace +'></a>';
}
}
</script>
</strong></td>
</tr>
<tr>
<td height="108" valign="top"> <form name="frm" action=#>
<DIV class=TRY>
<p align="center">Sila Pilih Bahagian/ Please Choose A Department:
</p>
<div align="center">
<select name="bahaGian" onChange="Department();" >
<option>Bahagian Cukai Dalaman</option>
<option>Bahagian Protokol</option>
<option>Bahagian Pencegahan</option>
<option>Bahagian Perkhidmatan Teknik</option>
<option>Cawangan Pengurusan</option>
<option>Cawangan Teknologi Maklumat</option>
</select>
</div>
</DIV>
</form>
<FORM name=Frm1 action=#>
<DIV class=TRY>
<p align="center">Sila Pilih Tarikh/ Please Choose The Date:<br>
Dari/From: <br>
<SELECT name=MoSel onchange="MonLen(YrSel, MoSel, DySel)" >
</SELECT>
-
<SELECT name=DySel>
</SELECT>
-
<select name=YrSel onChange="MonLen(YrSel, MoSel, DySel)" >
</select>
<script language="JavaScript">
document.write(DropReadYMD(YrSel, MoSel, DySel));
//the first date
</script>
</p>
</DIV>
</FORM>
<FORM name=Frm2 action=#>
<DIV class=TRY>
<div align="center">Hingga/To: <BR>
<SELECT name=Mos onchange="MonLen(Yrs, Mos, Dys)" >
</SELECT>
-
<SELECT name=Dys>
</SELECT>
-
<select name=Yrs onChange="MonLen(Yrs, Mos, Dys)" >
</select>
<script language="JavaScript">
document.write(DropReadYMD(Yrs, Mos, Dys));
//the second date
</script>
</div>
</DIV>
</FORM>
<form name="form1" method="post" action="file:///C|/My%20Documents/NANIE/NaniE/complain.php">
<p align="center">
<input onClick="Out.value=Display()" type=button name="Submit" value="Hantar">
<input type="reset" name="Reset" value="Padam">
<script language="JavaScript">
function Display()
{
function A ()
{
with (document.forms['Frm1']) { return DropReadYMD(YrSel, MoSel, DySel) }
//this function will give the format date yyyy-mm-dd
}
function B ()
{
with (document.forms['Frm2']) { return DropReadYMD(Yrs, Mos, Dys) }
}
var Z = A()
var Y = B()
return Z + ' ' + Y + ' ' + Department();
}
//i created this function to see how i can retrieve the selected options by user
//and how to manipulate the date. this function will be removed.
</script>
</p>
<p>
<input alt=" Result " name="Out" size="50">
</p>
</form>
<p>
<script type=text/javascript>
// Selector control :
var D_Opt = new Array() // 29..31
function MonLen(Yr, Mo, Dy) { var Dol, K, DiM, NsI
DiM = LengthOfMonth(+Yr.options[Yr.selectedIndex].text,
Mo.selectedIndex+1)
Dol = Dy.options.length
if ( (NsI = Dy.selectedIndex) >= DiM ) NsI = DiM-1
// for (K=Dol ; K >DiM ; K--) Dy.options[K-1] = null
// for (K=Dol+1 ; K<=DiM ; K++) Dy.options[K-1] = new Option(K)
for (K=Dol ; K >DiM ; K--)
{ D_Opt[K] = Dy.options[K-1] ; Dy.options[K-1] = null }
for (K=Dol+1 ; K<=DiM ; K++) Dy.options[K-1] = D_Opt[K]
Dy.selectedIndex = NsI }
// Demo function :
function DropReadYMD(Yr, Mo, Dy) {
var Y = + Yr.options[Yr.selectedIndex].text
var M = Mo.selectedIndex // 0..11
var D = Dy.selectedIndex + 1
return Y + '-' + Lz(M+1) + '-' + Lz(D); }
// Initialiser :
function InitYMDselector(Yr, Mo, Dy, Anni, Base, SetObj) { var J
if (!Base) Base = new Date().getFullYear()
for (J=0; J<Anni; J++) Yr.options[J] = new Option(Base+J)
for (J=0; J<12 ; J++) Mo.options[J] = new Option(Mon3[J])
for (J=0; J<31 ; J++) Dy.options[J] = new Option(J+1)
if (SetObj) with (SetObj) {
Yr.selectedIndex = getFullYear()-Base
Mo.selectedIndex = getMonth()
Dy.selectedIndex = getDate()-1 }
else Yr.selectedIndex = Mo.selectedIndex = Dy.selectedIndex = 0
MonLen(Yr, Mo, Dy) }
// Initialising ( Argument Now (optional) must be in BaseYear+YearSpan-1 ) :
var Now, YearSpan = 8,
BaseYear = (Now = new Date()).getFullYear() - 3
with (document.forms['Frm1'])
InitYMDselector(YrSel, MoSel, DySel, YearSpan, BaseYear, Now)
with (document.forms['Frm2'])
InitYMDselector(Yrs, Mos, Dys, YearSpan, BaseYear, Now)
</script>
</td>
</tr>
<tr>
<td height="13"></td>
</tr>
</table></td>
<td height="19"></td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="14"></td>
<td rowspan="2" valign="top">
<?
include("file:///C|/Documents%20and%20Settings/Administrator/My%20Documents/Unnamed%20Site%2025/dbinfo.inc.php");
mysql_connect('172.16.0.3',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
//'Tarikh'(bahasa Malaysia) is 'date' in english. All of the records in the database will be displayed in
//decending order by date.
$query="SELECT * FROM tblMklmBls1 ORDER BY Tarikh DESC" ;
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
</td>
<td></td>
<td></td>
<td></td>
<?php
//print ( "$num" )
//the number of records found.
?>
<td rowspan="2"></td>
<td></td>
</tr>
<tr>
<td height="22"></td>
<td></td>
<td colspan="2" align="center" valign="middle"><?php echo'<p><strong>Jumlah Rekod Ditemui:'.$num.'sahaja</strong></p>';?> </td>
<td></td>
</tr>
<tr>
<td height="385"></td>
<td colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="1" height="79"> </td>
<td width="565" valign="top"><table width="100%" bgcolor="#00CCFF" bordercolor="#3333FF" border="1" cellpadding="0" cellspacing="0" name="table0" id="table0" cols="7">
<tr>
<td width="32" height="40"><div align="center"><strong>Id</strong></div></td>
<td width="142"><div align="center"><strong>Nama</strong></div></td>
<td width="78"><div align="center"><strong>Kategori</strong></div></td>
<td width="98"><div align="center"><strong>Bahagian/ Cawangan</strong></div></td>
<td width="126"><div align="center"><strong>Tajuk</strong></div></td>
<td width="44"><div align="center"><strong>Tarikh</strong></div></td>
<td width="45"><div align="center"><strong>Status</strong></div></td>
</tr>
<?
$i=0;
while ($i < $num)
{
$datatime=mysql_result($result,$i,"Tarikh");
//Converts from MySQL date format (yyyy-mm-dd) to a format like dd/mm/yyyy.
$convertedDate = date("d/m/Y", strtotime ($datatime) );
//splitting date to different variable
list ($day, $month, $year) = split ('[/.-]', $convertedDate);
//i don't use these variables. i just want to see how it works.
$id=$i+1;
//declaration of variables
$Nama=mysql_result($result,$i,"Nama");
$Lokasi=mysql_result($result,$i,"Lokasi");
$Telefon=mysql_result($result,$i,"Telefon");
$Kategori=mysql_result($result,$i,"Kategori");
$Subjek=mysql_result($result,$i,"Subjek");
$Bahagian=mysql_result($result,$i,"Bahagian");
//bahagian is 'department' in english
$Pegawai=mysql_result($result,$i,"Pegawai");
$Organisasi=mysql_result($result,$i,"Organisasi");
$Kandungan=mysql_result($result,$i,"Kandungan");
$Emel=mysql_result($result,$i,"Emel");
//$Lokasi, $Telefon, $Emel, $Pegawai, $Kandungan, $Organisasi ->i don't use these variables on this page
//but on the other pages.
?>
<tr>
<td height="39" bgcolor="#EAEAEA" bordercolor="#0000FF"><div align="center">
<? echo "$id"; ?></div></td>
<td bgcolor="#EAEAEA" bordercolor="#0000FF"><div align="left"></div>
<a href="file:///C|/Documents%20and%20Settings/Administrator/My%20Documents/Unnamed%20Site%2025/printpage.php"><? echo "$Nama"; ?></a></td>
<td bgcolor="#EAEAEA" bordercolor="#0000FF"><div align="left"></div>
<? echo "$Kategori"; ?></td>
<td bgcolor="#EAEAEA" bordercolor="#0000FF"><div align="left"></div>
<? echo "$Bahagian"; ?></td>
<td bgcolor="#EAEAEA" bordercolor="#0000FF"><div align="left"></div>
<? echo "$Subjek"; ?></td>
<td bordercolor="#0000FF" bgcolor="#EAEAEA"><div align="left"></div>
<? echo "$convertedDate"; ?></td>
<?
++$i;
echo "</tr>";
}
//A record will be displayed by a row.
?>
</table></tr>
<tr>
<td height="304"> </td>
<td> </td>
</tr>
</table></td>
<td> </td>
<td></td>
<td></td>
</tr>
<tr>
<td height="64"></td>
<td> </td>
<td></td>
<td></td>
<td> </td>
<td></td>
<td></td>
</tr>
<tr>
<td height="22"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td> </td>
<td> </td>
</tr>
</table>
<?
/*
when a user choose the department and the date, then, by clicking the button-"Hantar/Submit",
i want to return the records that contains the department on specific date and display to
the next page. for example: complain.php
*/
?>
</body>
</html>

.. i really need help.. thankyou...