Forum Moderators: coopster

Message Too Old, No Replies

Could someone tell me what this is doing

         

GGR_Web

10:10 am on Feb 10, 2009 (gmt 0)

10+ Year Member



Hello.

Here's the code snippet

"SELECT * FROM product WHERE partno='%s'";

Could someone tell me what '%s' means in this case.
I understand % is the wildcard character which would mean I get results like 45s, flowers 1.3343445s ect.

But the actual results this query is actually giving bear no resemblance to that idea. Is 's' a special character under these conditions?

Still very much learning this stuff!

Sekka

10:25 am on Feb 10, 2009 (gmt 0)

10+ Year Member



Are you using sprintf() by any chance?

%s is a place holder for a string that will be inserted into the query.

There are others too, check out the manual.

[uk2.php.net...]

GGR_Web

11:34 am on Feb 10, 2009 (gmt 0)

10+ Year Member



Yes.

"SELECT * FROM product WHERE partno='%s'",$partno

So the string would be whatever happens to be the value of $partno

In that case this reads as:
SELECT all FROM product Where partno = partno

[edited by: GGR_Web at 11:41 am (utc) on Feb. 10, 2009]

Sekka

11:47 am on Feb 10, 2009 (gmt 0)

10+ Year Member



Exactly right. If you need the wildcard, you need to add another %, and possible escape it (\%).

GGR_Web

2:18 pm on Feb 10, 2009 (gmt 0)

10+ Year Member



Right.

That's cleared up then.