0

Hey guys I have a mysql database that has an events table. The events table consists of the fields Title, Date, Place and description. I am trying to display the table on the browser using php coding. it should list important events first according to the date. so as follows

title: xxx
date: xxx
Place:xxx
Description:xxxx

Here is my code so far but it does not seem to work the way I want it to to print the multiple events that may exists on screen in sequence of the date. Any help or advice is appreciated. Thanks

<?php

$con = mysql_connect("localhost", "root", "root") or die ("MYSQL connection error");

mysql_select_db (enetta, $con) or die("Unable to connect to the database");

?>
<!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=UTF-8" />
<title>Assignment1</title>
</head>

<body>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Assignment 1</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="generator" content="HAPedit 3.1">
<link rel="stylesheet" type="text/css" href="../styles/defaultpage.css"/>
</head>

<body>

<table width = 600 border = 1>
<tr> <td>
<table border = 1 align = "right">
<tr> <td> <a href = "addevents.php"> Add Events </td> </tr>
</table>
</td> </tr>
<tr> <td>
<table width = 200>
<?php

$sql = "SELECT Title, Date, Place, Description FROM Events";
$data = mysql_query($sql);
?>
<tr> <td> Title: </td>
<?php $row = mysql_fetch_array($data);

echo "<td>" .$row["Title"]. "</td>";
?>
</tr>
<tr> <td> Date: </td>
<?php $row = mysql_fetch_array($data);
$newDate = date("d-m-Y", strtotime($row["Date"]));
echo "<td>" .$newDate. "</td>";
?>
</tr>

<tr> <td> Place </td>
<?php $row2 = mysql_fetch_array($data);

echo "<td>" .$row["Place"]. "</td>";
?>
</tr>

<tr> <td> Description </td>
<?php $row2 = mysql_fetch_array($data);

echo "<td>" .$row["Description"]. "</td>";
?>
</tr>
</table>
</td> </tr>

</table>

</body>
</html>

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by simplypixie
0

@lizetta

In the future try to highlight the code and click "Code" on the text editor so it will appear light blue. So people can read it.

Here is my code so far but it does not seem to work the way I want it to to print the multiple events that may exists on screen in sequence of the date.

1) Are you connected to the database?
2) Can you select anything from the table?

0

You need to order the results in your query:

$sql = "SELECT Title, Date, Place, Description FROM Events ORDER BY Date ASC";

Either ASC or DESC depending which order you want them in

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.