Code: Select all
$Host = "localhost"; //you can use IP address instead of localhost
$User = "my_username";
$Password = "my_password";
$Database = "my_database";
$Link_ID=mysql_pconnect($Host, $User, $Password);
if (!$Link_ID)
{
echo "Failed to connect to Server=".$Host;
return 0;
}
else
{
echo "<B>Successfully to connected to Server </B>" .$Host;
}
if (!@mysql_select_db($Database,$Link_ID))
{
echo "<br>Cannot use database= " .$Database;
}
else
{
echo "<br> Successfully connected to database= " .$Database;
}
// Performing SQL query
$query = 'select dvd_title, avg(rating), dvd_rlsdate from dvd_ratings, dvd_titles where dvd_titles.dvd_id=dvd_ratings.dvd_id group by dvd_ratings.dvd_id limit 10';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($Link_ID);I have a call the a table style class in the html/css which specifies its position, font and background colour:
Code: Select all
table {color: #000060; border-collapse: seperate; border-spacing:2px; margin-top:150px; margin-left:390px; text-align: left; vertical-align: baseline; font-family:Verdana; font-size:11px; font-weight: bold; background: #fffff5;}regards,