Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Creating PHP printf string with database variables

Posted on 2004-10-24
8
Medium Priority
?
558 Views
Last Modified: 2013-12-12
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?
0
Comment
Question by:kkbenj
  • 4
  • 3
8 Comments
 
LVL 10

Assisted Solution

by:frugle
frugle earned 1000 total points
ID: 12393100
   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
 
LVL 7

Expert Comment

by:BenMorel
ID: 12393712
It seems correct to me.
Ben
0
 

Author Comment

by:kkbenj
ID: 12394069
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
BenMorel earned 1000 total points
ID: 12394109
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
 

Author Comment

by:kkbenj
ID: 12394126
I split the points because the first solution was missing the single quotation that I needed.

Thanks to both of you!
0
 

Author Comment

by:kkbenj
ID: 12394148
How can I add
onmouseover="window.status=' ';return true;"
to this string?
0
 
LVL 7

Expert Comment

by:BenMorel
ID: 12394200
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
 

Author Comment

by:kkbenj
ID: 12394215
Perfect!

You are fantastic!!!!!!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question