I a newbie with this language and I do not know how to make it.
So in here I have script like this :
<?php
include_once "library/inc.sesadmin.php";
include_once "library/inc.library.php";
$row = 20;
$hal = isset($_GET['hal']) ? $_GET['hal'] : 0;
$pageSql = "SELECT * FROM kategori";
$pageQry = mysql_query($pageSql, $koneksidb) or die ("error paging: ".mysql_error());
$jml = mysql_num_rows($pageQry);
$max = ceil($jml/$row);
?>
<table width="700" border="0" cellpadding="2" cellspacing="1" class="table-border">
<tr>
<td colspan="2" align="right"><h1><b>DATA KATEGORI</b></h1></td>
</tr>
<tr>
<td colspan="2"><img src="images/btn_add_data2.png" height="25" border="0" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><table class="table-list" width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<th width="32" align="center"><b>No</b></th>
<th width="93" align="center"><b>Kode</b></th>
<th width="444"><b>Nama Kategori </b></th>
<th width="93" align="center"><b>Jumlah Barang</b> </th>
<td width="47" align="center" bgcolor="#CCCCCC"><b>Ubah</b></td>
<td width="52" align="center" bgcolor="#CCCCCC"><b>Hapus</b></td>
</tr>
<?php
$kategoriSql = "SELECT kategori.*, (SELECT COUNT(*) FROM barang WHERE barang.kd_kategori=kategori.kd_kategori) As qty_barang
FROM kategori ORDER BY kd_kategori ASC LIMIT $hal, $row";
$kategoriQry = mysql_query($kategoriSql, $koneksidb) or die ("Query kategori salah : ".mysql_error());
$nomor = 0;
while ($kategoriRow = mysql_fetch_array($kategoriQry)) {
$nomor++;
$Kode = $kategoriRow['kd_kategori'];
?>
<tr>
<td align="center"><b><?php echo $nomor; ?></b></td>
<td align="center"><b><?php echo $kategoriRow['kd_kategori']; ?></b></td>
<td><?php echo $kategoriRow['nm_kategori']; ?></td>
<td align="center"><?php echo $kategoriRow['qty_barang']; ?></td>
<td align="center"><img src="images/btn_edit.png" width="20" height="20" border="0" /></td>
<td align="center"><img src="images/btn_delete.png" width="20" height="20" border="0" alt="Delete Data" /></td>
</tr>
<?php } ?>
</table></td>
</tr>
<tr>
<td><b>Jumlah Data :</b> <?php echo $jml; ?> </td>
<td align="right"><b>Halaman ke :</b>
<?php
for ($h = 1; $h <= $max; $h++) {
$list[$h] = $row * $h - $row;
echo " <a href='?page=Data-Kategori&hal=$list[$h]'>$h</a> ";
}
?>
</td>
</tr>
</table>
I want to make table sorting and search by at this table, but I do not know how to make it.
Can anyone help me for this simple project??
I really appreciate your big help in here..
I'm not going to give you the exact code because it's not how we do things in SO,
However I will share with you the main idea of how to accomplish it.
For each column add a link, for example:
<td><a href='?orderby=id'>ID</a></td>
<td><a href='?orderby=name'>Name</a></td>
When id and name are fields in the table (SQL & html).
Before the query you check if there's a LEGIT value for orderby ($_GET['orderby'])
and if so add it to the ORDER BY ... in the query.
Please notice that you're using mysql_* which is not safe (especially in this case),
consider using mysqli_* or PDO (you can google it)
EDIT
You can add &direction= to the columns' links to set the direction (DESC / ASC)
Related
PHP newbie here! I ve been struggling with this for a few days now and i have decided i cant figure this out on my own.
Basically i have 2 database tables "projects_2016" and "attachment".
I want to show the data of "projects_2016" to show in the top table and then check for a matching id number (and if it exsits) in "attachment" it will list all the results under the "project_2016 data".
At the moment it works great but it duplicates the "projects_2016" data for every "attachment" entry.
Here is my code, any input is appreciated!
PS not too concereded about Sql injections. Still learning that!
<?php include '../../../connection_config.php';
$sql = "SELECT DISTINCT * FROM attachment JOIN projects_2016 ON attachment.attachment_ABE_project_number = projects_2016.id ORDER BY `attachment_ABE_project_number` DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<table width="20" border="1" cellspacing="0" cellpadding="2">
<tr>
<th height="0" scope="col"><table width="990" border="0" align= "center" cellpadding="3" cellspacing="0">
<tr class="text_report">
<td width="107" height="30" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>PNo</strong></td>
<td width="871" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Project Name</strong></td>
</tr>
<tr>
<td height="20" align="left" valign="middle" bgcolor="#FFFFFF" class="text_report"><strong><?php echo "<br>". $row["ID"]. "<br>";?></strong></td>
<td height="20" align="left" valign="middle" bgcolor= "#FFFFFF" class="text_report"><strong><?php echo "<br>". $row["project_name"]. "<br>";?></strong></td>
</tr>
</table>
<?php
$photo_id = $row["ID"];
$contacts = "SELECT DISTINCT * FROM attachment WHERE attachment_ABE_project_number = '$photo_id'" ;
$result_contacts = $conn->query($contacts);
if ($result_contacts->num_rows > 0) {
// output data of each row
while($row_contacts = $result_contacts->fetch_assoc()) {
?>
<table width="990" border="0" align="center" cellpadding= "3" cellspacing="0" class="text_report">
<tr>
<td height="0" colspan="4" align="left" valign="middle" nowrap="nowrap" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td width="319" height="30" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>File Name</strong></td>
<td width="279" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>File Type</strong></td>
<td width="315" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>File Size (KB)</strong></td>
<td width="53" align="right" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>View File</strong></td>
</tr>
<tr>
<td height="20" align="left" valign="middle" bgcolor="#FFFFFF"><?php echo $row_contacts ['file'] ?></td>
<td height="20" align="left" valign="middle" bgcolor="#FFFFFF"><?php echo $row_contacts ['type'] ?></td>
<td height="20" align="left" valign="middle" bgcolor="#FFFFFF"><?php echo $row_contacts ['size'] ?></td>
<td align="right" valign="middle" bgcolor="#FFFFFF">view file</td>
</tr>
<tr>
<td height="0" colspan="4" align="left" valign="middle" bgcolor="#FFFFFF"> </td>
</tr>
<?php
}
?>
</table>
<?php
}
?></th>
</tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
<tr>
<th height="26"> </th>
</tr>
</table>
<p>
<?php
}
}
?>
</p>
</table>
<?php $conn->close();
?>
$sql = "SELECT * FROM projects_2016
WHERE EXISTS (SELECT * FROM attachment WHERE projects_2016.id = attachment_ABE_project_number) ORDER BY id DESC ";
Im trying to show the respective comments to the respective question ID but all the comments are shown in every post.
actually the value of qusetion ID is not going to the desired table where it suppose to be and that table
name: add_topic.php
<body>
<?php
$con=mysqli_connect('localhost','root','');
if(!$con)
{
die("could not connect to the server".mysqli_error());
}
mysqli_select_db($con,'forum');
// Get value of id that sent from hidden field
$id=$_POST['id'];
// Find highest answer number.
$q="SELECT MAX(a_id) AS Maxa_id FROM forum_ans WHERE que_id='$id'";
$result=mysqli_query($con,$q);
$row=mysqli_fetch_assoc($result);
// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1
if ($row) {
$Max_id = $row['Maxa_id']+1;
}
else {
$Max_id = 1;
}
// get values that sent from form
$a_name=$_POST['a_name'];
$a_email=$_POST['a_email'];
$a_ans=$_POST['a_ans'];
$datetime=date("d/m/y H:i:s"); // create date and time
// Insert answer
$q2="INSERT INTO forum_ans(que_id, a_id, a_name, a_email, a_ans, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_ans', '$datetime')";
$result2=mysqli_query($con,$q2);
if($result2){
echo "Successful<BR>";
echo "<a href='view_topic.php?id=".$id."'>View your answer</a>";
// If added new answer, add value +1 in reply column
$q3="UPDATE forum_que SET reply='$Max_id' WHERE id='$id'";
$result3=mysqli_query($con,$q3);
}
else {
echo "ERROR";
}
// Close connection
mysqli_close($con);
?>
</body>
block that named as que_id is showing the value of 0 (as i have set 0 as its default value) and that is the main reason of it but im not able to solve this problem. plz help...
name: view_topic.php
<body>
<?php
$con=mysqli_connect('localhost','root','');
if(!$con)
{
die("could not connect to the server".mysqli_error());
}
mysqli_select_db($con,'forum');
// get value of id that sent from address bar
$id=$_GET['id'];
$q="SELECT * FROM forum_que WHERE id='$id'";
$result=mysqli_query($con,$q);
$row=mysqli_fetch_assoc($result);
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong><?php echo $row['topic']; ?></strong></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><?php echo $row['detail']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>By :</strong> <?php echo $row['name']; ?> <strong>Email : </strong><?php echo $row['email'];?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/time : </strong><?php echo $row['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?php
// Switch to table "forum_answer"
$q2="SELECT * FROM forum_ans WHERE que_id='$id'";
$result2=mysqli_query($con,$q2);
while($row2=mysqli_fetch_assoc($result2)){
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong>ID</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><?php echo $row2['a_id']; ?></td>
</tr>
<tr>
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
<td width="5%" bgcolor="#F8F7F1">:</td>
<td width="77%" bgcolor="#F8F7F1"><?php echo $row2['a_name']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Email</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><?php echo $row2['a_email']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Answer</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><?php echo $row2['a_ans']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/Time</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><?php echo $row2['a_datetime']; ?></td>
</tr>
</table></td>
</tr>
</table><br>
<?php
}
$q3="SELECT view FROM forum_que WHERE id='$id'";
$result3=mysqli_query($con,$q3);
$row3=mysqli_fetch_assoc($result3);
$view=$row3['view'];
// if have no counter value set counter = 1
if(empty($view)){
$view=1;
$q4="INSERT INTO forum_que(view) VALUES('$view') WHERE id='$id'";
$result4=mysqli_query($con,$q4);
}
// count more value
$addview=$view+1;
$q5="update forum_que set view='$addview' WHERE id='$id'";
$result5=mysqli_query($con,$q5);
mysqli_close($con);
?>
<BR>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="add_ans.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="18%"><strong>Name</strong></td>
<td width="3%">:</td>
<td width="79%"><input name="a_name" type="text" id="a_name" size="45"></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td>:</td>
<td><input name="a_email" type="text" id="a_email" size="45"></td>
</tr>
<tr>
<td valign="top"><strong>Answer</strong></td>
<td valign="top">:</td>
<td><textarea name="a_ans" cols="45" rows="3" id="a_ans"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" value="<? echo $id; ?>"></td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
name: add_topic.php
<body>
<?php
// get data that sent from form
$topic=$_REQUEST['topic'];
$detail=$_REQUEST['detail'];
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$datetime=date("d/m/y h:i:s"); //create date time
$con=mysqli_connect('localhost','root','');
if(!$con)
{
die("could not connect to the server".mysqli_error());
}
mysqli_select_db($con,'forum');
$q="INSERT INTO`forum`.`forum_que`(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";
if(mysqli_query($con,$q))
{
echo '<script>alert("Data Inserted Now redirecting to login page");</script>';
header('location:main_forum.php');
}
else
{
echo "error inserting record" . mysqli_error($con,$query);
echo '<script>alert("Error while inserting data");</script>';
}
mysqli_close($con);
?>
</body>
You have two add_topic.php should one be add_ans.php
I don't see any exact problems with this code are you sure that the $id is being used correctly in the hidden field of your form?
Possibly try doing a print_r($_POST); on the add_ans.php page to see what data is actually being passed by the form
I can final exams assignment of lecturers to create a website forum.
and now there is a problem in my coding.
please fix.
when creating a topic / thread, and we opened the topic / threadnya, there is a date that tell us when the topic / thread made.
but in my coding, showing all existing date in the database.
<?php
session_start();
if($_SESSION['logged'] == true)
{
if(isset($_SESSION['username']))
{ echo $username=$_SESSION["username"];
}else
{
header('Location:login.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!==CSS>
<style>
#clock{
pointer-events: none
}
</style>
<!close css>
<img src="head1.jpg" alt="icon" width="100%" height="110">
<img src="line1.jpg" alt="icon" width="100%" height="20">
<title>Venray</title>
<body background="alienbackground.jpg">
<font face="comic sans MS">
<!==Table Login==>
<table border="0" style="width:99%" bgcolor="#424242" align="center">
<tr>
<table border="0" style="width:98%" bgcolor="#424242" align="center">
<tr>
<td> <img src="start.gif" alt="icon" width="26" height="26"> </td>
<td rowspan="2" align="right">
<table border="0" bgcolor="#2E2E2E">
<tr>
<td><b>
<?php
{
echo "<tr><td><b><font color=green> Welcome, ";
echo $username;
echo '<span>, [Log Out]</span></li>';
echo "</tr></td></b></font>";
}
?>
</b></td>
</tr>
<tr>
<td id=clock align="right"><b><iframe src="http://free.timeanddate.com/clock/i4eh41xm/n108/tlsg/fn7/fs12/tct/pct/ftb/tt0/tw1/tm1/th1" frameborder="0" width="182" height="20" allowTransparency="true"></iframe>
</b></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top"><b><font size="4">Community</font></b></td>
</tr>
</table>
</tr>
<p style="color:#ff0000">
<!==Table please welcome==>
<table border="0" style="width:98%" bgcolor="#424242" align="center">
<tr>
<td align="right">
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
require("conn.php");
$con = mysql_connect($server,$user,$pass);
$db = mysql_select_db($db);
$sql = "select * from d_admin order by username";
//echo $sql;
$ambil_data = mysql_query($sql);
while($data = mysql_fetch_array($ambil_data))
$result = mysql_query("SELECT * FROM d_admin");
$rows = mysql_num_rows($result);
echo "Member " . $rows . " * ";
?>
Post 1 * Topics 1 </td>
</tr>
</table>
<br>
<table border="1" width="98%" height="6%" align="center" bgcolor=#424242 >
<tr>
<td align="left" ><img src="hometopic.gif" width="40" height="40"> </td>
</tr>
<tr>
<table border="1" width="98%" height="40" align="center" bgcolor="#86B404" bordercolor=green>
<tr>
<th width="70%" align="left"><img src="open.png" width="40" height="40">Posting Display</th>
<td align="right"><img src="replay.png" width="150" height="40"></td>
</tr>
</tr>
<tr>
<table border="1" width="98%" height="70" align="center" bgcolor=#424242>
***<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$con = mysql_connect($server,$user,$pass);
$db = mysql_select_db($db);
$sql = "select * from tabel_topik ";
$ambil_data = mysql_query($sql);
while($data = mysql_fetch_array($ambil_data))
{
echo '<tr><th align="left" valign="top" colspan="2" >'.$data['date'].'</th></tr>';
echo '</tr>';
}
?>***
<tr><th align="center" width="15%">Venray</th><td align="left" width="85%">title</td></tr>
<tr><th align="top" width="15%">join dates</th><td align="left" rowspan="2" valign="top">awd</td></tr>
<tr><th align="center" valign="top" width="15%" height="400">9 Post</th></tr>
<tr>
<td align="left">*</td>
<td align="right" width="85%"><img src="replay.png" width="150" height="40"></td></tr>
</table>
</tr>
</table>
</body>
</font>
</head>
</html>
Get forum specific datas by passing the ID or any similar field in the query for starters. Then if you are looking to format the way in which the date is displayed, you could use the php date function like this:
while($data = mysql_fetch_array($ambil_data))
{
echo '<tr><th align="left" valign="top" colspan="2" >'.date('jS M, Y',strtotime($data['date'])).'</th></tr>'; //format the date as required
echo '</tr>';
}
Hello I'm trying to update this scholarship application box. However when the year changed to 2013 it only displays scholarship applicant info from 2013. I'd like it to display info from 2012. I tried messing around with the date but I cant seem to figure it out. Any help would be greatly appreciated!
<?php
$appYear = date("Y").'-'.(date("Y")+1);
$sql = 'select * from sApplication where studentID = "'.$database->iPrep($_SESSION['ID']).'" AND appYear = "'.$appYear.'" LIMIT 1';
$appID = Scholarship::iFindSQL($sql);
$total = count($appID);
if ($total > 0)
{
$app = array_shift($appID);
}
else
{
$app = 0;
}
?>
<li id="item-2">
<div id="appStatus">
<h3>Application Status</h3>
<blockquote>
<?php if ($app->submitted == ('0000-00-00') || !isset($app->submitted)) { ?>
<table style="border:1px solid #000;" width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="50%"><strong>Scholarship<br /> 2013-2014</strong></td>
<td width="50" align="right"> <a style="font-size:16px;" href="welcome.php? app=Scholar">Apply Now</a></td>
</tr>
<tr>
<td><strong>Date Submitted</strong></td>
<td align="right"> </td>
</tr>
<tr>
<td><strong>References</strong></td>
<td align="right"> </td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td> </td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<tr>
<td><strong>Scholarship 2012-2013</strong></td>
<td> </td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td> </td>
</tr>
</table>
<?php } else { ?>
<table style="border:1px solid #000;" width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="90%"><strong>Scholarship 2013-2014</strong></td>
<td width="10%" align="right"> </td>
</tr>
<tr>
<td><strong>Date Submitted</strong></td>
<td align="right"><?=dbOutDate($app->submitted)?></td>
</tr>
<tr>
<td><strong>References</strong> </td>
<td align="right"></td>
</tr>
<tr>
<td colspan="2">
<?php
$refs = Reference::iFindSQL("Select * from reference where appID = '".$app->ID."'");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php foreach($refs as $ref) { ?>
<tr> <td> <small><?php if($ref->rType == 'Academic Reference'){ echo 'Academic/Artistic/Professional'; } else { echo 'Community Service'; } ?></small></td> <td align="right"><?=$ref->status?></td></tr>
<?php } ?>
</table>
</td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td align="right">
<?php
if ($app->complete == 'Approved') { echo 'Approved'; }
if ($app->complete == 'Declined') { echo 'Declined'; }
if ($app->complete == 'Pending') { echo 'Pending'; }
if ($app->complete == 'Incomplete') { echo 'Incomplete'; }
Remove the WHERE clause that limits the year. Use ORDER BY to sort by year, descending.
$sql = 'select * from sApplication
where studentID = "'.$database->iPrep($_SESSION['ID']).
'" ORDER BY appYear DESC LIMIT 1';
I used the following code to display the event details fetched from the database.
<form name="event_form" id="event_form" action="" method="post" enctype="application/x-www-form-urlencoded">
<table width="765" border="0" align="left" cellpadding="0" cellspacing="0" >
<tr>
<td>
<table width="765" border="0" align="left" cellpadding="0" cellspacing="0" id="results" class="fronttbl">
<tr></tr>
<?php
$select = "SELECT * FROM `tbl_event`";
$select_event = mysql_query($select);
$select_num = mysql_num_rows($select_event);
if($select_num > 0)
{
while($fetch = mysql_fetch_array($select_event))
{
$feventid=$fetch['intEventid'];
$feventname=stripslashes(ucfirst($fetch['varEventname']));
$fDate=$fetch['varDate'];
$seperate=explode("-", $fDate );
$year=$seperate[0];
$month=$seperate[1];
$date=$seperate[2];
$fchiefguest=stripslashes(nl2br($fetch['varChiefguest']));
$fvenue=stripslashes($fetch['varVenue']);
$ftime=stripslashes($fetch['varTime']);
$feventdetails=stripslashes($fetch['varEventdetails']);
echo " ";
?>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="30%" height="30" valign="top"><strong>Name of the event:</strong></td>
<td width="70%" height="30" valign="top"><?php echo $feventname; ?></td>
</tr>
<tr>
<td height="30" valign="top"><strong>Date of the event to be held:</strong></td>
<td height="30" valign="top"><?php echo $date.'-'.$month.'-'.$year; ?></td>
</tr>
<tr>
<td height="30" valign="top"><strong>Time of the Event:</strong></td>
<td height="30" valign="top"><?php echo $ftime; ?></td>
</tr>
<tr>
<td height="30" valign="top"><strong>Venue of the event:</strong></td>
<td height="30" valign="top"><?php echo $fvenue; ?></td>
</tr>
<tr>
<td height="30" valign="top"><strong>Name of the Chief Guest:</strong></td>
<td height="30" valign="top"><?php echo $fchiefguest; ?></td>
</tr>
<tr>
<td height="30" valign="top"><strong>Event Details:</strong></td>
<td height="30" valign="top"><?php echo $feventdetails; ?></td>
</tr>
</table>
<p style="border-bottom:1px dotted #CCCCCC;"></p>
</td></tr>
<?php }
}
?>
</table>
</td>
</tr>
</table>
<div id="pageNavPosition"></div>
</form>
I have date field in my database table and the input will be saved like the following format 2012-03-01.
I need my page displays the events order by recent date/month/year in the frontend. For example today's event should displayed first likewise. How can i do that?
Use ORDER BY (...is that what you meant)?
Change your query to:
SELECT *
FROM `tbl_event`
ORDER BY varDate DESC
as i understand use this function for front end:
function changeFormat( $date ){
$exp_date = explode('-', $date);
return $exp_date[2] . '-'.$exp_date[1].'-'.$exp_date[0];
}
example: echo changeFormat('2012-12-01'); will return 01-12-2012 and apply this in your while loop where you want to display your date