Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript Site
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

US Job listings




   Misc

   Amazon

   Links

    


A daily link example

 

The next possible scenario. You want to display a different link depending on the day of the week. The script below shows how this could be achieved.


 

 

<?php
//use the getdate function to retrieve the date/time data
$today = getdate();
//store the day of the week in the $day variable
$day = $today['wday'];
//increment the variable by 1 because the wday returns 0 to 6 to represent Sunday to Saturday
//Our database ID starts at 1
$day = $day + 1;
//connect to server with username and password
$connection = mysql_connect ("localhost","username", "password") or die ("Cannot make the connection");
//connect to database
$db = mysql_select_db ("test",$connection) or die ("Cannot connect to database");
//our SQL query we will display the id equivalent to the $day variable
$sql_query = "SELECT * FROM test WHERE id LIKE $day";
//store the SQL query in the result variable
$result = mysql_query($sql_query);
if(mysql_num_rows($result))
{
//output as long as there are still available fields
while($row = mysql_fetch_row($result))
{
echo ("<a href=\"$row[2]\">$row[3]</a>");
echo (": $row[4]<br>");
}
}
//if no fields exist
else
{
echo "no values in the database";
}

?>

here is the result (if you come back tomorrow it will be a different link)



 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
Do While loop(PHP)
While loop example(Javascript)
change file extensions(VB)
Glowing text in Internet Explorer(Javascript)
a simple dialog box using swing(Java)
gethostbyname function(PHP)
insert contents of text file into a text box(VB)
Count the occurences of a SubSTring(VB.net)

    




Copyright © 2004 by programmershelp.co.uk