Main Menu

HOME

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

US Job listings




   Misc

   Amazon

   Links

    


Displaying the last 5 winning draws

 

OK this is fairly straightforward . On to the script, then we will look at certain parts of it.

 

Script

<?php
//include our database config file
require_once("dbvariables.php");
//our SQL query
$sql_query = "SELECT * FROM lotto LIMIT 0,5";
//store the SQL query in the result variable
$result = mysql_query($sql_query);
if(mysql_num_rows($result))
{
echo "<table border=\"1\" cellpadding=\"4\" cellspacing =\"4\">";
echo "<tr>";
echo "<td>Date</td><td>Ball 1</td><td>Ball 2</td><td>Ball 3</td><td>Ball 4</td>";
echo "<td>Ball 5</td><td>Ball 6</td><td>Bonus Ball</td><td>Ball Set</td><td>Machine Used</td>";
echo "</tr>";
//output as long as there are still available fields
while($row = mysql_fetch_row($result))
{
echo "<tr>";
echo "<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td>";
echo "<td>$row[5]</td><td>$row[6]</td><td>$row[7]</td><td>$row[8]</td><td>$row[9]</td>";
echo "</tr>";
}
echo "</table>";
}
//if no fields exist
else
{
echo "no values in the database";
}

?>


 

In detail

require_once("dbvariables.php");

This is our file containing the database information.

$sql_query = "SELECT * FROM lotto LIMIT 0,5";

This is our SQL query in this case we are only selecting 5 rows from the lotto table and we are starting at the very first row 0.

echo "<table border=\"1\" cellpadding=\"4\" cellspacing =\"4\">";
echo "<tr>";
echo "<td>Date</td><td>Ball 1</td><td>Ball 2</td><td>Ball 3</td><td>Ball 4</td>";
echo "<td>Ball 5</td><td>Ball 6</td><td>Bonus Ball</td><td>Ball Set</td><td>Machine Used</td>";
echo "</tr>";

This is just HTML output to display the headings at the top of the table.

while($row = mysql_fetch_row($result))
{
echo "<tr>";
echo "<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td>";
echo "<td>$row[5]</td><td>$row[6]</td><td>$row[7]</td><td>$row[8]</td><td>$row[9]</td>";
echo "</tr>";
}
echo "</table>";

The lines above loop through the rows returned and output them in the table. This could be done cleverer with loops but thats another code example to come :-).

 


 

 

see the example here

 

 

 

 



   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
Function example(C++)
Size of a webpage with PHP and cURL(PHP)
Display all sub-folders of a given path(VBNet)
change computer name(Visual Basic)
network client information(VBScript)
backup a folder to a zip file(PHP)
Create a folder(ASP)
Display all drives(VB)

    




Copyright © 2004 by programmershelp.co.uk