Adding Hyperlinks to scraped data
Posted: Sun Dec 17, 2006 12:26 pm
Hi guys,
I have a table of results pulled from a mysql database which is printed to html using the code below. I now want to add hyperlinks to each record for taking the visitor to the details page of each record. I guess its a case of adding another table to the database containing the hyperlinks with matching ids, but i have no idea how to go about writing the php code for it. Please advise.
I have a table of results pulled from a mysql database which is printed to html using the code below. I now want to add hyperlinks to each record for taking the visitor to the details page of each record. I guess its a case of adding another table to the database containing the hyperlinks with matching ids, but i have no idea how to go about writing the php code for it. Please advise.
Code: Select all
$Host = "hostname"; //you can use IP address instead of localhost
$User = "username";
$Password = "password";
$Database = "databasename";
$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= ";
}
// Performing SQL query
$query = "select dvd_title, round(avg(rating),1) AS rounded_rating , date_format(dvd_rlsdate,'%d %b %y') from dvd_ratings, dvd_titles where dvd_titles.dvd_id=dvd_ratings.dvd_id group by dvd_ratings.dvd_id order by rounded_rating desc limit 10";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
$odd = true;
echo "<table>\n";
echo "<tr><th>Title</th><th>Rating</th><th>DVD Release Date</th></tr>"; // Setting Column Names
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($odd) echo "\t<tr bgcolor=\"#CCF1FF\">\n";
else echo "\t<tr bgcolor=\"#FBF6D5\">\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
$odd = !$odd;
}
echo "</table>\n";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($Link_ID);