After spending the required amount of time with family and such, I went right back to this little project I've started on. I found something called str_replace and played around with that for a while.
So here it is:
<?php
$dbhost = "localhost";
$dbname = "test";
$dbuser = 'mike';
$dbpass = '******';
mysql_connect("$dbhost", "$dbuser", "$dbpass") or die(mysql_error());
mysql_select_db('test') or die(mysql_error());
// This is the general links table
$result = mysql_query("SELECT * FROM links WHERE head like 'general'") or die(mysql_error());
$row_count = mysql_num_rows($result) or die(mysql_error());
echo "<table class=\"footcollapse\">";
echo "<thead>\n<tr>\n<th colspan=\"3\" align=\"center\">" . General . "</th>\n</tr>\n</thead>\n";
echo "<tfoot>\n<tr>\n<td colspan=\"3\">expand / collapse</td>\n<tr>\n</tfoot>";
echo "<tr>\n<th>URL</th><th>Description</th><th>Hits</th>\n</tr>\n";
//find out how many rows were returned
while($row = mysql_fetch_array($result)) {
if($row_count % 2) { //if the number of this of this row (not the id form the db) is even...
$rowc = "#001155"; //...than make this the tr's bgcolor
} else { //If it's odd...
$rowc = "#225588"; //...make tr use this bgcolor
}
$base = $row['url'];
echo "<tr bgcolor=\"$rowc\"><td>"; //new table row, with alternating bgcolors
$go = 'redir.php?go=http://' . $row['url'];
echo '<a href="' . rawurldecode($go) . '" target="0">' . $base . '</a>'; //grab the url twice: once for the href, and once for the clickey
echo '</td><td>';
echo $row['descrip']; //populate the description for the url
echo '</td><td>';
echo $row['hits']; //this is the field that I would like to increment via some kinda click tracking
echo '</td></tr>';
$row_count++; //this is the way we count the rows, count the rows, count the rows...
}
echo "</table>\n";
echo "<br />\n";
?>
As for the script redir.php, (which seemed to be the fun part)
<?php
if (isset($_GET['go'])) {
// redirect browser to clicked url
$go = rawurldecode($_GET['go']);
$url = str_replace('http://','',$_GET['go']); //here's where we strip off the "http://"
header("Location: " . $go);
// meanwhile count the click
$dbhost = "localhost";
$dbname = "test";
$dbuser = "mike";
$dbpass = "*******";
mysql_connect("$dbhost", "$dbuser", "$dbpass");
mysql_select_db("test");
$sql = "UPDATE links SET hits=hits+1 WHERE url='".$url."'";
mysql_query($sql);
} else {
header("Location: http://localhost:85/links.php");
}
?>
So here I am with a completely customized hit counting table of links... and no static route 🙁
Thanks so much guys for your help with this!