Forum Moderators: coopster

Message Too Old, No Replies

Formatting SQL Query / DB field

         

dave1236

8:07 pm on Sep 8, 2006 (gmt 0)

10+ Year Member



All:

I have just encountered an interesting (to me) issue. I have implemented a Database solution and the queries necessary to make it happen (special thanks to Coopster!). However, now my tracking code that I append to my links no longer register...they just print out.

Here is what I have done:

1) created a field called link (with text attributes) in my DB.
2) inserted a link with tracking code in that field
(for example:
<a target="_blank" href="http://abc.com/click.abc.com/fs-bin/click?id=abc&offerid=123.10&type=4&subid=0&u1=<?php print $_SESSION[tracking];?>" ><img alt="Item" border="0" src="http://www.abc.com/images/iiii468.gif" ></a><img border="0" width="1" height="1" src="http://www.abc.com/fs-bin/show?id=abc&bids=64878.10&type=4&subid=0" >

When the link prints in my web page, the output for u1 is <?php print $_SESSION[tracking];?>

any ideas why that is? is it because I have defined the field as text? should it be VARCHAR - if so, how do I create a filed large enough to handle such a long link?

In case you were wondering about my query, here it is:

<?php
include("dbconnect.inc");
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$today = date("Y-m-d");
$_SESSION['tracking']=$_SESSION[logname];
$dealtype = "New Deals"; //Deal Type
$query = "SELECT * FROM Links WHERE DATE_SUB(CURDATE(),INTERVAL 5 DAY) <= entry AND expire > '$today' ORDER BY entry DESC";
$result = mysql_query($query)
or die ("Couldn't execute query.");

/* Display results in a table */
$dealtype = ucfirst($dealtype);
echo "<h1>$dealtype</h1>";
echo "<table cellspacing='15'>";
echo "<tr><td colspan='3'><hr></td></tr>";
while ($row = mysql_fetch_array($result))
{
extract($row);
$f_price = number_format($price,2);
echo "<tr>\n
<td>$store</td>\n
<td>$link</td>\n
<td>Expires $expire</td>\n
</tr>\n";
echo "<tr><td colspan='3'><hr></td></tr>\n";
}
echo "</table>\n";
?>

Much thanks!

eelixduppy

8:25 pm on Sep 8, 2006 (gmt 0)



You cannot do somthing like this, really. The php within the url has to be interpreted by PHP. When you pull it from the table, it is taken as text, not PHP. And is not interpretted as such. If you want, you can do something along these lines:

Put this into the DB:
<a target="_blank" href="http://abc.com/click.abc.com/fs-bin/click?id=abc&offerid=123.10&type=4&subid=0&u1=TRACKING" ><img alt="Item" border="0" src="http://www.abc.com/images/iiii468.gif" ></a><img border="0" width="1" height="1" src="http://www.abc.com/fs-bin/show?id=abc&bids=64878.10&type=4&subid=0" >

And then echo it like this:


while ($row = mysql_fetch_array($result))
{
extract($row);
$f_price = number_format($price,2);
echo "<tr>\n
<td>$store</td>\n
<td>".str_replace("TRACKING",$_SESSION['tracking'],$link)."</td>\n
<td>Expires $expire</td>\n
</tr>\n";
echo "<tr><td colspan='3'><hr></td></tr>\n";
}

Something like that. Good luck!

dave1236

12:52 am on Sep 9, 2006 (gmt 0)

10+ Year Member



Thanks a bunch!

This seems to work perfectly!