Wow php is a beautifull thing. I've got it working just as I wanted!
Thanks alot for your help toplay.
One last thing. If use this script for multiple links on the one page do I do it like this:
<?php
// Connect to MySQL server first – You can use variables instead of these literals
$db = mysql_connect('localhost', 'username', 'password');
if (!$db) {
echo 'Could not connect to MySQL server. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error();
exit;
}
// Select the database you want to use – You can use a variable here too instead
if (!mysql_select_db('china', $db)) { // Did selection fail?
// Handle error
echo 'DB Selection failed. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error();
exit;
}
?>
<?php
$category = mysql_escape_string('Teas'); // or use addslashes()
$sql = "SELECT number FROM navigation WHERE name = '$category'";
$result = mysql_query($sql, $db);
if (!$result) {
// Handle error
echo 'Query failed. SQL: ', $sql, '<br />Error # ', mysql_errno(), ' Error msg: ', mysql_error();
exit;
}
$row = mysql_fetch_assoc($result); // Try to retrieve the data
if (!$row) // No data returned?
// Not necessarily an error – Just no data matched search criteria
echo 'No data found <br />';
else // There is valid data returned
printf("<a href=\"http://www.site.com/body$number.htm\"><img src=image.gif border=0></a>");
?>
<?php
$category = mysql_escape_string('Link2); // or use addslashes()
$sql = "SELECT number FROM navigation WHERE name = '$category'";
$result = mysql_query($sql, $db);
if (!$result) {
// Handle error
echo 'Query failed. SQL: ', $sql, '<br />Error # ', mysql_errno(), ' Error msg: ', mysql_error();
exit;
}
$row = mysql_fetch_assoc($result); // Try to retrieve the data
if (!$row) // No data returned?
// Not necessarily an error – Just no data matched search criteria
echo 'No data found <br />';
else // There is valid data returned
printf("<a href=\"http://www.site.com/body$number.htm\"><img src=image.gif border=0></a>");
?>