[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Creating PHP printf string with database variables

Posted on 2004-10-24
8
Medium Priority
?
556 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 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