Creating PHP printf string with database variables

I need to build into my currently functioning printf() string a variable pulled from my mySql table.

Here's the existing code:
<?php
$atsign="@";
$today = Date("Y-m-d");
$startdt = date('Y-m-d', strtotime('-5 days'));

$db = mysql_connect("localhost", "root");
mysql_select_db("fullinfo",$db);
$sql = "SELECT SUBSTRING_INDEX(wemail,'@',1) as 'leftemail',SUBSTRING_INDEX(wemail,'@',-1) as 'rightemail',SUBSTRING_INDEX(wemail,'.',-1) as 'dotcom',date_format(wdate,'%b %e') as 'thedate', DATE_FORMAT(wdate,'%Y-%M-%e') as passdate,wstate FROM w100 where wdate>='$startdt' and wdate<'$today' order by wdate desc";
$result = mysql_query($sql,$db) or die("Couldn`t execute query");

if ($myrow = mysql_fetch_array($result)) {

  do {

    printf("<tr><td height=24><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></td><td><a href='/cgi-bin/tixcheck.cgi?t=XXX target='_blank'><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></a></td></tr>\n", $myrow["thedate"], substr($myrow["leftemail"],0,1)."____$atsign".substr($myrow["rightemail"],0,1)."_____.".$myrow["dotcom"]);

  } while ($myrow = mysql_fetch_array($result));

}

?>

The above works correctly.  Now I need to replace the XXX in the a href string with $myrow["passdate"] variable pulled from my table.

How can this be done?
kkbenjAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
BenMorelConnect With a Mentor Commented:
This is correct :

printf("<tr><td height=24><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></td><td><a href='/cgi-bin/tixcheck.cgi?t=%s' target='_blank'><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></a></td></tr>\n", $myrow["thedate"], $myrow["passdate"], substr($myrow["leftemail"],0,1)."____$atsign".substr($myrow["rightemail"],0,1)."_____.".$myrow["dotcom"]);

It was : =%s'
And not :f ='%s

Regards,
Ben
0
 
frugleConnect With a Mentor Commented:
   printf("<tr><td height=24><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></td><td><a href='/cgi-bin/tixcheck.cgi?t=%s target='_blank'><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></a></td></tr>\n", $myrow["thedate"], $myrow["passdate"], substr($myrow["leftemail"],0,1)."____$atsign".substr($myrow["rightemail"],0,1)."_____.".$myrow["dotcom"]);


unless I'm mistaken.

Mike
0
 
BenMorelCommented:
It seems correct to me.
Ben
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
kkbenjAuthor Commented:
I used this:
 printf("<tr><td height=24><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></td><td><a href='/cgi-bin/tixcheck.cgi?t=%s target='_blank'><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></a></td></tr>\n", $myrow["thedate"], $myrow["passdate"], substr($myrow["leftemail"],0,1)."____$atsign".substr($myrow["rightemail"],0,1)."_____.".$myrow["dotcom"]);

and it gave an error:
Parse error: parse error, unexpected T_STRING in ctop10.php on line 139 (this is the printf line)

 So I added the ' to make it:
    printf("<tr><td height=24><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></td><td><a href='/cgi-bin/tixcheck.cgi?t='%s target='_blank'><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></a></td></tr>\n", $myrow["thedate"], $myrow["passdate"], substr($myrow["leftemail"],0,1)."____$atsign".substr($myrow["rightemail"],0,1)."_____.".$myrow["dotcom"]);

This got rid of the error, but the date is not part of the link URL.

What am I missing?
0
 
kkbenjAuthor Commented:
I split the points because the first solution was missing the single quotation that I needed.

Thanks to both of you!
0
 
kkbenjAuthor Commented:
How can I add
onmouseover="window.status=' ';return true;"
to this string?
0
 
BenMorelCommented:
I think this is what you want :

printf("<tr><td height=24><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></td><td><a href='/cgi-bin/tixcheck.cgi?t=%s' target='_blank' onmouseover=\"window.status=' ';return true;\"><font style='font-family:arial,helvetica,sans-serif;color: #335399;font-size: 12px;'>%s</font></a></td></tr>\n", $myrow["thedate"], $myrow["passdate"], substr($myrow["leftemail"],0,1)."____$atsign".substr($myrow["rightemail"],0,1)."_____.".$myrow["dotcom"]);

(You need to replace " with \")
0
 
kkbenjAuthor Commented:
Perfect!

You are fantastic!!!!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.