Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the significance of "%s" 1

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
I am putting a php/MYSQL page together with the help of Dreamweaver2004, a tiny bit of knowledge and guesswork.
The code I have arrived at works, but I'd like to know why!
<?php
//set up recordset
$colname_rstSix = "1";
if (isset($_GET['email'])) {
$colname_rstSix = (get_magic_quotes_gpc()) ? $_GET['email'] : addslashes($_GET['email']);
}
mysql_select_db($database_tormented3, $tormented3);
$query_rstSix = sprintf("SELECT ck_organisation FROM chk_sixmonth WHERE ck_email = '%s'", $colname_rstSix);
$rstSix = mysql_query($query_rstSix, $tormented3) or die(mysql_error());
$row_rstSix = mysql_fetch_assoc($rstSix);
$totalRows_rstSix = mysql_num_rows($rstSix);
?>
My particular interest at the moment is the significance of the '%s'. I see no reference to it elsewhere in the code.
What is its function here?
 
The %s is a string placeholder or variable that gets "filled in" with the string value passed in after the comma.

Example 1:
print sprintf("My name is %s", 'Dave');
%s in this case will be filled in with the word - Dave.

Example 2:
print sprintf("I am %d years old", 35);
%d is an integer placeholder. In this case, it will be filled in with the integer 35.

Example 3:
print sprintf("I am %d years old", 'Dave');
Here, %d will be 0 as 'Dave' is a string, not an integer.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top