<?php
# SQL> CREATE TABLE keywords (
# 2 kwID INT AUTO_INCREMENT PRIMARY KEY,
# 3 keyword VARCHAR(64) );
#
# SQL> CREATE TABLE url_title (
# 2 urlID INT AUTO_INCREMENT PRIMARY KEY,
# 3 url VARCHAR(128),
# 4 title VARCHAR(128) );
#
# SQL> CREATE TABLE www_index (
# 2 kwID INT,
# 3 urlID INT,
# 4 PRIMARY KEY ( kwID, urlID ),
# 5 FOREIGN KEY ( kwID ) REFERENCES keywords ( kwID ),
# 6 FOREIGN KEY ( urlID ) REFERENCES url_title ( urlID ) );
include 'password.php'; // Containing only one line: $password="your-pw";
$keyword = $argv[1];
$username = "your-id@undcsmysql";
$database = "your-db";
$host = "undcsmysql.mysql.database.azure.com";
$conn = new mysqli( $host, $username, $password, $database );
if ( $conn->connect_error )
die( 'Could not connect: ' . $conn->connect_error );
# SELECT k.keyword, u.url, u.title FROM keywords k, url_title u, www_index w
# WHERE k.keyword LIKE '%$keyword%' AND k.kwID=w.kwID AND w.urlID=u.urlID;
$no = 1;
$sql = "SELECT k.keyword, u.url, u.title FROM keywords k, url_title u, www_index w WHERE ";
$sql .= "k.keyword LIKE '%" . $keyword . "%' AND k.kwID=w.kwID AND w.urlID=u.urlID;";
echo( $sql );
echo( "<table width='98%' border='1' bgcolor='lightyellow'>" );
echo( "<tr><th width='05%'>No.</th>" );
echo( "<th width='15%'>Keyword</th>" );
echo( "<th width='30%'>URL</th>" );
echo( "<th width='50%'>Title</th></tr>" );
$result = $conn->query( $sql );
if ( $result->num_rows > 0 )
while( $row = $result->fetch_assoc( ) ) {
echo( "<tr><td>". $no++ . "</td><td>" . $row[keyword] );
echo( "</td><td><a target='_blank' href='" . $row[url] . "'>" . $row[url] );
echo( "</a></td><td>" . $row[title] . "</td></tr>" );
}
echo( "</table>" );
$conn->close( );
?>
|