PHP and mySQL
Moderator: General Moderators
PHP and mySQL
I want to create a script.
It has to go to my database and select all the data then display it it the date that will come first. Eg. One event on 1st augyst will be shown above one on the 2nd of august.
I also need a script to add data the the database using the following fields:
match_name
match_date (this is what the most recent can be displayed on)
match_time
match_venue
Any help appreciated!
It has to go to my database and select all the data then display it it the date that will come first. Eg. One event on 1st augyst will be shown above one on the 2nd of august.
I also need a script to add data the the database using the following fields:
match_name
match_date (this is what the most recent can be displayed on)
match_time
match_venue
Any help appreciated!
Is it a mySql database? Select all the data in the database or just in a specific table?
If it is mysql try:
You need to set $servername, $username, $password, $database, and $table as appropriate.
If it is mysql try:
Code: Select all
//connect to server and select database
$con = mysql_connect($servername, $username, $password);
if (!$con)
{
die('Could not connect :' . mysql_error());
}
//select database
mysql_select_db($database, $con);
//create and execute query
$sql="SELECT * FROM ".$table." ORDER BY match_date ASC"; //ASC so oldest are at the top
$result=mysql_query($sql);
//iterate through resulting rows
while($row=mysql_fetch_array($result))
{
echo $row['match_name']." ".$row['match_date']." ".$row['match_time']." ".$row['match_venue']."<br>";
}Try:
match_date will have to be stored in a field of type 'DATE' for this to work.
Code: Select all
//connect to server and select database
$con = mysql_connect($servername, $username, $password);
if (!$con)
{
die('Could not connect :' . mysql_error());
}
//select database
mysql_select_db($database, $con);
//create and execute query
$sql="DELETE FROM ".$table." WHERE match_date<CURDATE()";
$result=mysql_query($sql);- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
So you don't want to be able to see them ever, from any interface in the future? Your users don't want to see what has happened in the past?mademokid wrote:I dont want the match to be displayed after that date it is on though.
There are no inputs required by robshanks' code if I read it correctly.. and proper coding practices are used.mademokid wrote:And also if i use roboshanks code what format does the input have to be?