Question : Modifying a Script: Ajax/PHP request to MySQL DB

Hello,
I would like to use the following script
that displays tooltips by displaying content from external files fetched by AJAX. Instead of using external files, I would like to display information fetched from a MySQL database, passing a parameter in the URL to get the appropriate record. Can someone help with the AJAX code to fetch from a DB instead of an external file?
You can familiarize yourself with the script by going here:http://www.dhtmlgoodies.com/index.html?whichScript=ajax-tooltip.
Thanks,


Answer : Modifying a Script: Ajax/PHP request to MySQL DB

Instead if specifying a static page like html:


you will need to provide a dynamic page like php:


Then your php page just needs to query the db:
$dbServer="localhost";
$dbName="foo";
$link = mysql_connect( $dbServer, 'mysql_user', 'mysql_password');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db($dbName, $link);
if (!$db_selected) {
    die ("Can't use $dbName : " . mysql_error());
}

$result = mysql_query("SELECT description FROM tableName WHERE id=" . $_GET['id'] ) or die( mysql_error());

$row=mysql_fetch_assoc($result);
echo $row['description'];
mysql_close();
?>
Random Solutions  
 
programming4us programming4us