Jump to content

[SOLVED] sprintf() function


arusha

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.