select problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

select problem

Post by potato »

Hi,

i am wondering how i can select where the word start with the letter a for example?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

as in results from a MySQL table?

Make use of the % sign, its a wildcard like * is.

=]

SELECT field_name FROM table_name WHERE field_name LIKE 'a%';
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post by potato »

thanx
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

very welcome.

:wink:
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post by potato »

this is my query:

mysql_select_db($database_memberships, $memberships);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE username like '%m%'");
$Recordset1 = mysql_query($query_Recordset1, $memberships) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1); ?>


and this i get as result:

Warning: sprintf(): Too few arguments in /home/httpd/vhosts/bevibed.be/httpdocs/TMPmw0dswcaeq.php on line 5
Query was empty


What did i wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sprintf requires more than one argument because you passed it a special character % without escaping it. It appears that you want to set $query_Recordset1 to that string..

Code: Select all

$query_Recordset1 = "SELECT * FROM users WHERE username like '%m%'";
Post Reply