printf and the "%" symbol
Posted: Mon Mar 08, 2004 12:31 am
I finally got a mySQL query to work, woohoo, but then they had to throw a monkey wrench in there with the printf function. Here's the code:
The for loop was my doing, it actually just had each printf function for the data. My question to you is this... what is the % symbol used for? The tut said something about a variable-somethin in Perl/C. What does the printf function do that echo can't? I see that there are 2 arguements, but what are they?
I looked at php.net....
-S
Code: Select all
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("user",$db);
$result = mysql_query("SELECT * FROM employees",$db);
for($i=0;$i<3;$i++){
printf("First Name: %s<br>\n", mysql_result($result, $i, "first"));
printf("Last Name: %s<br>\n", mysql_result($result, $i, "last"));
printf("Address: %s<br>\n", mysql_result($result, $i, "address"));
printf("Position: %s<br>\n", mysql_result($result, $i, "position"));
echo "<br>";
}
?>I looked at php.net....
-S