PDA

View Full Version : tracking codes


elbyweb
17-03-2006, 21:13/09:13PM
i want to add a small script that uses SSI to relay info about the vistor. i have the script up and running my problem is i have no idea about mysql and every page on my site is a result of a sql quarry.

also would it be easy for me to make the article updater insert the tracking code with each article that is made?

?

WebSavvy
17-03-2006, 21:35/09:35PM
Firstly, what's the tracking script written in?

Is it in Perl or is it in PHP?

If it's in Perl, you can use SSI to include it.
If it's in PHP you'll need to do a PHP include.

If the script is written in PHP the page it's being included in must be .php because you can't include a php file into a plain HTML page unless you add an Apache handler for the document type in your .htaccess file.

Making a connection to MySQL is easy. You'll need to know the db_name, db_user, db_pass and db_table.

In your file that will connect to MySQL add the following lines:


$connection = @mysql_connect("localhost" , "db_user" , "db_pass") or die (" Could not connect to the server. ");
$db = @mysql_select_db("db_name" , $connection) or die (" Could not select database. ");



Replace db_user with your database username
Replace db_pass with your database password
Replace db_name with the name of your database

Then to do an SQL query, you'd need to select the fields to be queried in an SQL statement followed by a while loop.

A typical SQL query would look like this:


$sql = "select field1, field2, field3 from db_table";
$sql_result = mysql_query($sql , $connection) or die ("Couldn't execute query.");

while ($row = mysql_fetch_array($sql_result))
{
$field1 = $row["field1"];
$field2 = $row["field2"];
$field3 = $row["field3"];

// what you want from it goes here

} // end while loop

Replace field1, field2, field3 -- with your actual field names from your database table.

Replace db_table in the SQL statement with the name of your table from your database.

HTH

elbyweb
17-03-2006, 21:46/09:46PM
thanks sorted!! wow im totally shocked i understood everything you said. im going to do the coding part when the sun comes up though (to much work no sleep)