arusha Posted April 4, 2008 Share Posted April 4, 2008 I'm new to PHP, so I'm trying to learn by example. I tested the following example code and it works fine: <?php class PersonService { function PersonService() { include("PersonService.methodTable.php"); mysql_connect('localhost', 'root', ''); mysql_select_db('amfphp'); } /** * Gets the people between age min and age max * @access remote */ function getPerson($ageMin, $ageMax) { $sql = sprintf("SELECT uid AS data, ". "CONCAT(first_name, ' ', last_name, ' (', age, ' years old)') AS label ". "FROM person WHERE age >= %d AND age <= %d", $ageMin, $ageMax); $query = mysql_query($sql); return $query; } } ?> Then I tried to make some minor modifications so that it would search by a person's first name. i'm guessing this should involve really simple changes, but all I can get it to return using this code is 'FALSE'. class ToolbarService { function ToolbarService() { include("ToolbarService.methodTable.php"); mysql_connect('localhost', 'root', ''); mysql_select_db('amfphp'); } /** * Gets the people depending on name * @access remote */ function getPerson($name) { $sql = sprintf("SELECT uid AS data, ". "CONCAT(first_name, ' ', last_name, ' (', age, ' years old)') AS label ". "FROM person WHERE first_name = %s", $name); $query = mysql_query($sql); return $query; } } ?> I've tried other variations where I use == or === to compare the strings, but to no avail. Am I doing something stupid? ??? Link to comment https://forums.phpfreaks.com/topic/99574-solved-sprintf-function/ Share on other sites More sharing options...
arusha Posted April 4, 2008 Author Share Posted April 4, 2008 Sorry, have just realised I'm being ridiculous and need to use '%s' instead of just %s. i'd have thought the tutorial i was using would mention this crucial detail! Link to comment https://forums.phpfreaks.com/topic/99574-solved-sprintf-function/#findComment-509427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.